【问题标题】:Two Command in Button TkinterButton Tkinter 中的两个命令
【发布时间】:2023-03-03 23:08:01
【问题描述】:

我想要两个将这两个命令放在一个按钮中。我使用 for 循环来生成网格按钮。

PC=Button(pc_area, text='RESERVE').pack()
PC['command'] = lambda PC=PC:reserve_confirmation(PC)
PC['command'] = lambda x=line: func(x)

【问题讨论】:

  • PC 是None,因为pack() 返回None。因此,在一行中实例化Button,然后将其打包到另一行中。要调用多个事件处理程序,请使用 Button(root, command=lambda :fun1() or fun2())

标签: python-3.x tkinter tkinter-button


【解决方案1】:

我试试这个,效果很好。

PC['command'] = lambda PC=PC,x=line:[reserve_confirmation(PC),func(x)]

【讨论】:

  • 或者您可以在按钮本身的声明期间定义命令。问题也应该在帖子中而不是在答案中提出。
猜你喜欢
  • 1970-01-01
  • 2011-10-18
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多