FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-130482: Add ability to specify name for `tkinter.OptionMenu` and `tkinter.ttk.OptionMenu` by Xiaokang2022 · Pull Request #130502 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,9 @@ tkinter
arguments passed by keyword.
(Contributed by Zhikang Yan in :gh:`126899`.)

* Add ability to specify name for :class:`!tkinter.OptionMenu` and
:class:`!tkinter.ttk.OptionMenu`.
(Contributed by Zhikang Yan in :gh:`130482`.)

turtle
------
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_tkinter/test_widgets.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ def test_bad_kwarg(self):
with self.assertRaisesRegex(TclError, r"^unknown option -image$"):
tkinter.OptionMenu(self.root, None, 'b', image='')

def test_specify_name(self):
widget = tkinter.OptionMenu(self.root, None, ':)', name="option_menu")
self.assertEqual(str(widget), ".option_menu")
self.assertIs(self.root.children["option_menu"], widget)

@add_configure_tests(IntegerSizeTests, StandardOptionsTests)
class EntryTest(AbstractWidgetTest, unittest.TestCase):
_rounds_pixels = (tk_version < (9, 0))
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_ttk/test_extensions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ def cb_test(*args):
textvar.trace_remove("write", cb_name)
optmenu.destroy()

def test_specify_name(self):
textvar = tkinter.StringVar(self.root)
widget = ttk.OptionMenu(self.root, textvar, ":)", name="option_menu_ex")
self.assertEqual(str(widget), ".option_menu_ex")
self.assertIs(self.root.children["option_menu_ex"], widget)


class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ def __init__(self, master, variable, value, *values, **kwargs):
keyword argument command."""
kw = {"borderwidth": 2, "textvariable": variable,
"indicatoron": 1, "relief": RAISED, "anchor": "c",
"highlightthickness": 2}
"highlightthickness": 2, "name": kwargs.pop("name", None)}
Widget.__init__(self, master, "menubutton", kw)
self.widgetName = 'tk_optionMenu'
menu = self.__menu = Menu(self, name="menu", tearoff=0)
Expand Down
3 changes: 2 additions & 1 deletion Lib/tkinter/ttk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,8 @@ def __init__(self, master, variable, default=None, *values, **kwargs):
A callback that will be invoked after selecting an item.
"""
kw = {'textvariable': variable, 'style': kwargs.pop('style', None),
'direction': kwargs.pop('direction', None)}
'direction': kwargs.pop('direction', None),
'name': kwargs.pop('name', None)}
Menubutton.__init__(self, master, **kw)
self['menu'] = tkinter.Menu(self, tearoff=False)

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ability to specify name for :class:`!tkinter.OptionMenu` and
:class:`!tkinter.ttk.OptionMenu`.

Back | FazBrowse Home | New Git URL