diff options
Diffstat (limited to 'Lib/idlelib/dynOptionMenuWidget.py')
-rw-r--r-- | Lib/idlelib/dynOptionMenuWidget.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Lib/idlelib/dynOptionMenuWidget.py b/Lib/idlelib/dynOptionMenuWidget.py index 877ca1b..515b4ba 100644 --- a/Lib/idlelib/dynOptionMenuWidget.py +++ b/Lib/idlelib/dynOptionMenuWidget.py @@ -2,17 +2,15 @@ OptionMenu widget modified to allow dynamic menu reconfiguration and setting of highlightthickness """ -from tkinter import OptionMenu, _setit, Tk, StringVar, Button - import copy -import re +from tkinter import OptionMenu, _setit, StringVar, Button class DynOptionMenu(OptionMenu): """ unlike OptionMenu, our kwargs can include highlightthickness """ def __init__(self, master, variable, value, *values, **kwargs): - #get a copy of kwargs before OptionMenu.__init__ munges them + # TODO copy value instead of whole dict kwargsCopy=copy.copy(kwargs) if 'highlightthickness' in list(kwargs.keys()): del(kwargs['highlightthickness']) @@ -35,22 +33,24 @@ class DynOptionMenu(OptionMenu): if value: self.variable.set(value) -def _dyn_option_menu(parent): - root = Tk() - root.title("Tets dynamic option menu") - var = StringVar(root) - width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) - root.geometry("+%d+%d"%(x, y + 150)) +def _dyn_option_menu(parent): # htest # + from tkinter import Toplevel + + top = Toplevel() + top.title("Tets dynamic option menu") + top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200, + parent.winfo_rooty() + 150)) + top.focus_set() + + var = StringVar(top) var.set("Old option set") #Set the default value - dyn = DynOptionMenu(root,var, "old1","old2","old3","old4") + dyn = DynOptionMenu(top,var, "old1","old2","old3","old4") dyn.pack() def update(): - dyn.SetMenu(["new1","new2","new3","new4"],value="new option set") - - button = Button(root, text="Change option set", command=update) + dyn.SetMenu(["new1","new2","new3","new4"], value="new option set") + button = Button(top, text="Change option set", command=update) button.pack() - root.mainloop() if __name__ == '__main__': from idlelib.idle_test.htest import run |