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
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to