diff options
Diffstat (limited to 'Lib/idlelib/dynOptionMenuWidget.py')
-rw-r--r-- | Lib/idlelib/dynOptionMenuWidget.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/idlelib/dynOptionMenuWidget.py b/Lib/idlelib/dynOptionMenuWidget.py index 922de96..877ca1b 100644 --- a/Lib/idlelib/dynOptionMenuWidget.py +++ b/Lib/idlelib/dynOptionMenuWidget.py @@ -2,9 +2,10 @@ OptionMenu widget modified to allow dynamic menu reconfiguration and setting of highlightthickness """ -from tkinter import OptionMenu -from tkinter import _setit +from tkinter import OptionMenu, _setit, Tk, StringVar, Button + import copy +import re class DynOptionMenu(OptionMenu): """ @@ -33,3 +34,24 @@ class DynOptionMenu(OptionMenu): command=_setit(self.variable,item,self.command)) 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)) + var.set("Old option set") #Set the default value + dyn = DynOptionMenu(root,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) + button.pack() + root.mainloop() + +if __name__ == '__main__': + from idlelib.idle_test.htest import run + run(_dyn_option_menu) |