我在python tkinter GUI中有一些lambda函数。当我运行该程序时,我收到此错误,但我不确定它的含义。
_tkinter.TclError: bad option "-command": must be -column, -columnspan, -in, -ipadx,
-ipady, -padx, -pady, -row, -rowspan, or -sticky
这是我的代码包含函数:
self.sendbutton = Button(self, text = "Send")
self.sendbutton.grid(row = 2, column = 0, command = lambda: self.sendMessage())
def sendMessage(self):
print "Your message was sent."
答案 0 :(得分:1)
command
应该是按钮构造函数的参数,而不是grid
方法:
self.sendbutton = Button(self, text = "Send", command = lambda: self.sendMessage())
self.sendbutton.grid(row = 2, column = 0)
您向grid
提供的唯一参数是那些控制窗口小部件在窗口中网格化的参数。