2013-07-26 30 views
0

所以我有這個按鈕,多數民衆贊成由開始的東西,像這樣允許按鈕時控制已經去世

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") 

一種考慮循環的每次迭代的布爾之後。停止功能將改變更新爲false,這樣的循環

def stop(self): 
    permission = False 

然而,當我點擊「開始」我想控制不再是主循環和按鈕都沒有反應,儘管按鈕改變其屬性運行時間的持續時間。我怎樣才能使按鈕響應,以便它可以被打斷?

回答

1

在循環的每次迭代調用self.update(),這樣應用程序可以服務於兩個屏幕刷新事件和按鈕按下事件(假設self指Tkinter的部件)

相關問題