我有一個帶有可編輯文本字段的Tix.ComboBox。我如何強制保持文本值更新的變量?如何更新Tix.ComboBox的文本?
讓我給出更具體的解釋。我有一個組合框和一個按鈕。當我點擊按鈕時,它會彈出一個消息框,其中包含組合框的值。假設組合框文本字段當前具有值「thing1」。如果我在框中鍵入「新」,然後用鼠標點擊按鈕,它將彈出消息「thing1」。如果我在框中鍵入「新的」,然後選項卡遠離組合框,然後單擊按鈕彈出消息顯示「新」。
我該如何強制組合框將其值更新爲新的,而不要求我遠離組合框?
我已經包含示例代碼。
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()
注意,這個答案只存在被選爲*的*答案,這樣的問題不顯示未答覆;如果你想upvote它,你最好upvote Moe的答案(http://stackoverflow.com/questions/117211/how-to-update-a-tixcomboboxs-text#117384) – tzot 2008-10-29 18:24:04