Open jason990420 opened 3 years ago
Thank you for figuring this one out. I recall there being a tricky problem with generating the callback (finding the right bind) and I see that it's not a bind that's used like in other Widgets.
It's been very very interesting also to see the use of write_event_value recently by code that is not a thread. It had not occurred to me when it was written how useful this function would be for non-threaded problems.
Following code for your reference,
import tkinter as tk
def func(select):
print(f'You select {select.get()}')
root = tk.Tk()
root.wm_title("Message Demo")
items = ('Train', 'Plane', 'Boat')
select = tk.StringVar()
select.set('Selection')
font = ('Courier New', 20, 'bold')
option_menu = tk.OptionMenu(root, select, *items)
option_menu.config(font=font, width=10)
option_menu.pack()
select.trace_add("write", lambda *_, select=select:func(select))
root.mainloop()
Type of Issue (Enhancement, Error, Bug, Question)
Enhancement
Operating System
WIN10
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Version information can be obtained by calling
sg.main_get_debug_data()
Or you can print each version shown in ()Python version (
sg.sys.version
)3.9.5
PySimpleGUI Version (
sg.__version__
)4.45.0
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)8.6.9
Your Experience In Months or Years (optional)
2+ Years Python programming experience
10+ Years Programming experience overall
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine) yes, tkinter
Anything else you think would be helpful? No
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
There's no option
enable_events
for elementsg.OptionMenu
, so no event generated when content changed. Remove remark at line # 23 to make it work.Code To Duplicate
Screenshot, Sketch, or Drawing