我使用Tkinter在
python中创建了一个简单的组合框,我想检索用户选择的值.搜索之后,我想我可以通过绑定选择事件并调用一个将使用类似box.get()的函数来完成此操作,但这不起作用.程序启动时,会自动调用该方法,并且不会打印当前选择.当我从组合框中选择任何项目时,不会调用任何方法.这是我的代码片段:
self.box_value = StringVar()
self.locationBox = Combobox(self.master, textvariable=self.box_value)
self.locationBox.bind("<>", self.justamethod())
self.locationBox['values'] = ('one', 'two', 'three')
self.locationBox.current(0)
这是我从框中选择项目时应该调用的方法:
def justamethod (self):
print("method is called")
print (self.locationBox.get())
谁能告诉我如何获得所选值?
编辑:我已经纠正了对justamethod的调用,通过在将盒子绑定到James Kent建议的函数时删除括号.但现在我收到了这个错误:
TypeError:justamethod()只取1个参数(给定2个)
编辑2:我已经发布了这个问题的解决方案.
谢谢.