I am having a problem setting the initial value in the new Tkinter tix module. Can anyone help me out?

# explore the tix.ComboBox()
# the Tix (Tk Interface Extension) module comes with the
# Python27 and Python31+ installation

try:
    import Tix as tix  # Python27
except ImportError:
    import tkinter.tix as tix  # Python31+

def selected(event):
    sf = "value is %s" % combo.entry.get()
    root.title(sf)
    # optional
    color = combo.entry.get()
    root['bg'] = color


root = tix.Tk()
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
root.title("tix.ComboBox()")

combo = tix.ComboBox(root)
combo.pack(side='left', padx=10, pady=10)

# set the initial color
# can't get this to work!!!!!!!!!
combo.entry.insert(0, 'red')

# load the combobox listbox part
color_list = ['red', 'green', 'blue', 'yellow', 'white', 'magenta']
for item in color_list:
    combo.slistbox.listbox.insert('end', item)

# left mouse click on a list item to display selection
combo.slistbox.listbox.bind('<ButtonRelease-1>', selected)

root.mainloop()

This seems to get there, but I do not know if it is the most beautiful method:

# explore the tix.ComboBox()
# the Tix (Tk Interface Extension) module comes with the
# Python27 and Python31+ installation

try:
    import Tix as tix  # Python27
except ImportError:
    import tkinter.tix as tix  # Python31+

def selected(event):
    sf = "value is %s" % combo.entry.get()
    root.title(sf)
    # optional
    color = combo.entry.get()
    root['bg'] = color


root = tix.Tk()
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
root.title("tix.ComboBox()")

combo = tix.ComboBox(root)
combo.pack(side='left', padx=10, pady=10)


# load the combobox listbox part
color_list = ['red', 'green', 'blue', 'yellow', 'white', 'magenta']

for item in color_list:
    combo.slistbox.listbox.insert('end', item)

# set the initial color
combo.configure(value='red')
selected(None)

# left mouse click on a list item to display selection
combo.slistbox.listbox.bind('<ButtonRelease-1>', selected)

root.mainloop()
commented: great +6

It is beautiful tony! You are a genius! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.