Message279176
I did some experiments that cleared up some previous puzzlements about seemingly inconsistent behavior between interactive commands and those in scripts. The following prints '.mycombo' twice, on two lines, after selecting 'beta'.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
#root.withdraw()
cb = ttk.Combobox(root, name='mycombo', values=('alpha', 'beta'))
cb.pack()
def here(event): print(event.widget)
cb.bind('<<ComboboxSelected>>', here)
cb.set('none')
root.update()
cb.event_generate('<Button-1>')
root.update()
cb.event_generate('<Key-Down>')
root.update()
cb.event_generate('<Key-Return>')
root.update()
cb.event_generate('<<ComboboxSelected>>')
root.update()
cb.set does *not* trigger ComboboxSelected. Key_Return after Button-1 does. So does directly generating the event.
Uncomment .withdraw() and Key-Return does not trigger. But the directly generating the pseudoevent still works. About a month ago, I added .withdraw to tests to stop (obnoxious) screen flashes. I don't call it for shell interaction. Removing at least some of the .update()s will also stop triggering. In IDLE's interactive mode, tcl update is called 20 times a second, which is at least once per statement types and entered. Hence scripted and interactive statements had different effects.
Directly simulating user actions is more satisfying than generating the pseudoevent, but IDLE tests do not need to verify that Combobox works as advertised -- there is a ttk gui test for that. So I believe set('value') + generate('ComboboxSelected') should be sufficient on the input end (after conversion to Combobox and event binding). |
|
Date |
User |
Action |
Args |
2016-10-22 02:00:24 | terry.reedy | set | recipients:
+ terry.reedy, markroseman, jfoo |
2016-10-22 02:00:24 | terry.reedy | set | messageid: <1477101624.19.0.107961430125.issue27755@psf.upfronthosting.co.za> |
2016-10-22 02:00:24 | terry.reedy | link | issue27755 messages |
2016-10-22 02:00:23 | terry.reedy | create | |
|