from Tkinter import *
class Program:
def __init__(self):
b = Button(text="click me", command=self.callback("1"))
b.pack()
def callback(self,s):
print "clicked!"
program = Program()
mainloop()
为什么在点击按钮之前执行功能? * /
答案 0 :(得分:0)
您应该将函数引用传递给command
参数。否则你就可以执行该功能了。
b = Button(text="click me", command=self.callback)
# Or if you want to pass parameters
b = Button(text="click me", command=lambda: self.callback("1"))