如何更新 Tix.ComboBox 的文本?
我有一个带有可编辑文本字段的 Tix.ComboBox。 如何强制更新保存文本值的变量?
让我给出更具体的解释。 我有一个组合框和一个按钮。 当我单击该按钮时,它会弹出一个消息框,其中包含组合框的值。 假设组合框文本字段当前的值为“thing1”。 如果我在框中输入“new”,然后用鼠标单击按钮,则会弹出消息“thing1”。 如果我在框中键入“新”,然后将焦点从组合框移开,然后单击按钮,弹出消息将显示“新”。
如何强制组合框将其值更新为新值,而不需要我按 Tab 键离开组合框?
我已经包含了示例代码。
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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:可以选择 Moe 答案的副本作为所选答案
哇!
我自己解决了。
使用
而不是
NOTE: copy of Moe's answer that can be selected as chosen answer
woo!
solved it on my own.
Use
instead of
哇!
我自己解决了。
使用
而不是
woo!
solved it on my own.
Use
instead of