0
我有一套方法在我的程序中使用Tkinter,它的行为不像我认为的那样。我希望能够在窗口中按下按钮并显示更多文本字段,并且能够在文本字段中返回结果列表。以下是我有:Tkinter意外的行为
def expandChoice(self):
root = Tk()
choices = []
plusButton = Button (root, text='+', command=self.addChoice(root, choices))
plusButton.pack()
quitButton = Button (root, text='Ok', command=root.destroy)
quitButton.pack()
root.mainloop()
return choices
def addChoice(self, parent, variables):
variables.append(StringVar())
text = Entry(parent, textvariable=variables[len(variables)-1])
text.pack()
什么情况是,一个文本框,当窗口负载(上面的按钮),以及加号按钮不会显示任何内容。我究竟做错了什么?看起来像第一个按钮的构造函数被调用时自动调用addChoice方法,然后在此之后不起作用。
[Tkinter按钮命令可能在运行程序时激活?](http://stackoverflow.com/questions/3704568/tkinter-button-command-activates-upon-running-program) –