How could/would one programmatically open/close a ttk combobox (i.e.
present/hide the list of values) without requiring the user to click on
combobox down arrow? In other words, I want to programmatically change focus (from where ever it is) to the combobox and have the combobox list of values displayed (just as if I had clicked on the combobox down arrow control). I fiddled around with setting state (['pressed'] and ['focus']) but didn't succeed accomplishing this. Trevor _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
On 07/09/11 10:07, Trevor J Christensen wrote:
> How could/would one programmatically open/close a ttk combobox (i.e. > present/hide the list of values) without requiring the user to click on > combobox down arrow? > > In other words, I want to programmatically change focus (from where ever > it is) to the combobox and have the combobox list of values displayed > (just as if I had clicked on the combobox down arrow control). I > fiddled around with setting state (['pressed'] and ['focus']) but didn't > succeed accomplishing this. > I haven't delved too deeply into ttk yet, but I know how to solve your problem using Python Megawidgets (Pmw) instead. PMW example: from Tkinter import * import Pmw root = Tk() c = Pmw.ComboBox(root, scrolledlist_items=['1','2','3']) c.pack() c.selectitem('1') def dropdown(): c.invoke() b = Button(root, text='test', command=dropdown) b.pack() root.mainloop() Worked it out in ttk. You need to generate a button 1 event on the combobox. ttk example: from Tkinter import * import ttk root = Tk() c = ttk.Combobox(root) c.pack() c['values'] = ['1','2','3'] def dropdown(): c.event_generate('<Button-1>') b = Button(root, text='test', command=dropdown) b.pack() root.mainloop() Regards, John -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
In reply to this post by Trevor J Christensen
Hi Trevor,
Thus spoketh Trevor J Christensen <[hidden email]> unto us on Tue, 06 Sep 2011 18:07:49 -0600 (MDT): > How could/would one programmatically open/close a ttk combobox (i.e. > present/hide the list of values) without requiring the user to click on > combobox down arrow? > > In other words, I want to programmatically change focus (from where > ever it is) to the combobox and have the combobox list of values > displayed (just as if I had clicked on the combobox down arrow > control). I fiddled around with setting state (['pressed'] and > ['focus']) but didn't succeed accomplishing this. there seems to be no "post()" method or something like that for the ttk.Combobox, but what you want can be done with a little trickery: from Tkinter import * import ttk class ComboBox(ttk.Combobox): def __init__(self, *args, **kw): ttk.Combobox.__init__(self, *args, **kw) def post(self, event=None): self.update_idletasks() x, y = self.winfo_x(), self.winfo_y() self.event_generate('<1>', x=x+self.winfo_width()-3, y=y+3) root = Tk() c = ComboBox(root, values=('foo', 'bar', 'baz')) c.set('foo') c.pack(padx=50, pady=50) e = Entry(root) e.pack(pady=(0,50)) e.focus() root.bind('<F1>', c.post) root.mainloop() I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No one can guarantee the actions of another. -- Spock, "Day of the Dove", stardate unknown _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
Free forum by Nabble | Edit this page |