Python使用Tk按钮

2024-04-20 10:28:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是pythongui(TK)。我有一个按钮,运行一个漫长的过程-但我希望它被禁用后,立即点击它。 看起来是这样的:

button = tk.Button(self, text="blabla", command= lambda: self.foo(param, button)
def foo(self, button):
      button.configure (state = "disabled")
      #now call the function that takes time
      goo()
def goo():
   doLongAction()

问题是只有在goo()返回,然后foo返回之后,按钮才被禁用。 有没有办法马上禁用它? 谢谢


Tags: textselffoo过程defbutton按钮command
1条回答
网友
1楼 · 发布于 2024-04-20 10:28:55

通过调用^{}方法禁用按钮小部件后,需要更新它:

button = tk.Button(self, text="blabla", command= lambda: self.foo(param, button)
def foo(self, button):
      button.configure (state = "disabled")
      ##########################
      button.update_idletasks()
      ##########################
      #now call the function that takes time
      goo()
def goo():
   doLongAction()

相关问题 更多 >