views:

690

answers:

2

I have a Tix.ComboBox with an editable text field. How do I force the variable holding the value for the text to update?

Let me give a more concrete explanation. I have a combo box and a button. When I click the button, it pops up a message box with the value of the combo box. Let's say the combo box text field currently has the value "thing1". If I type "new" into the box and then click on the button with my mouse, it will pops up the message "thing1". If I type "new" in the box and then tab focus away from the combo box and then click the button the pop up message says "new".

Ho do I force the combo box to update it's value to new without requiring that I tab away from the combo box?

I have included sample code.

import Tix
import tkMessageBox

class App(object):
    def __init__(self, window):
        window.winfo_toplevel().wm_title("test")
        self.window = window

        self.combo = Tix.ComboBox(window)
        self.combo.insert(Tix.END, 'thing1')
        self.combo.insert(Tix.END, 'thing2')
        self.combo.entry['state'] = "normal"
        self.combo['editable'] = True
        self.combo.pack()

        button = Tix.Button(window)
        button['text'] = "Go"
        button['command'] = self.go
        button.pack()

    def go(self):
        tkMessageBox.showinfo('info', self.combo['value'])


if __name__ == '__main__':
    root = Tix.Tk()
    App(root)
    root.mainloop()
+2  A: 

woo! solved it on my own.

Use

self.combo['selection']

instead of

self.combo['value']
Moe
+1  A: 

NOTE: copy of Moe's answer that can be selected as chosen answer

woo! solved it on my own.

Use

self.combo['selection']

instead of

self.combo['value']
ΤΖΩΤΖΙΟΥ
Note that this answer exists only to be chosen as *the* answer, so that the question does not show up as unanswered; if you want to upvote it, you better upvote Moe's answer ( http://stackoverflow.com/questions/117211/how-to-update-a-tixcomboboxs-text#117384 )
ΤΖΩΤΖΙΟΥ