當我運行此代碼一切似乎工作正常,然後當我點擊我的藍色按鈕,我期待我的時間倒計時開始顯示按鈕文本改爲函數my_time在0x000000 ...等一些內存位置im努力尋找解決方案。如果它不清楚我試圖做什麼是文本藍色魔法變爲倒計時。錯誤當試圖顯示一個計時器到按鈕文本
from Tkinter import *
import os
import time
class Application(Frame):
@staticmethod
def my_time(self): # creates a timer starting at 5 min , counts down to 0 then repeats
min = 4
sec = 59
while sec <=60:
os.system('cls')
print min, "Minutes", sec, "Seconds"
time.sleep(1)
sec -= 1
if sec == 0:
min -= 1
sec = 59
elif min == 0:
min = 4
def my_time2(self): # tries to display my_time method into the button font, doesnt seem to work.
self.Button1["text"] = str(self.my_time)
def createButtons(self): # creats a button
self.Button1 = Button(self)
self.Button1["text"] = "Blue Buff"
self.Button1["fg"] = "Blue"
self.Button1["command"] = self.my_time2 # suppose to implement countdown in button text when click.
# currently problematic?
self.Button1.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master) # initializes window
self.pack()
self.createButtons()
root = Tk()
app = Application(master=root)
app.mainloop()
你'my_time'功能需要正確的縮進 – Shadow9043