【问题标题】:Allowing a button to be pressed when control has been passed away允许在控制权被传递时按下按钮
【发布时间】:2013-07-26 20:40:27
【问题描述】:

所以我有这个按钮来启动东西,就像这样

self.buttontext = StringVar()
self.buttontext.set("Start")
self.button = Button(self.bottomframe, textvariable=self.buttontext, command=self.start)

当它启动时,我希望用户能够在需要时将其缩短,方法是在启动后立即将同一个按钮更改为停止按钮

def start(self):
    self.button.config(command=self.stop)
    self.buttontext.set("Stop")
    permission = True
    for ...
        if update:
            run properly
        else:
            end prematurely

    self.button.config(command = self.start)
    self.buttontext.set("Start")

在循环的每次迭代中都考虑一个布尔值。 stop 函数会将 update 更改为 false 以便循环

def stop(self):
    permission = False

但是,在我单击“开始”后,我猜想控件不再在主循环中并且按钮没有响应,尽管按钮在运行时期间更改了其属性。我怎样才能使按钮响应,以便它可以被打断?

【问题讨论】:

    标签: python button tkinter


    【解决方案1】:

    在循环的每次迭代中调用 self.update(),以便应用程序可以同时服务屏幕刷新事件和按钮按下事件(假设 self 指的是 tkinter 小部件)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多