Terry J. Reedy added the comment:

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).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27755>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to