在做一些学习python / tkinter的活动时,我遇到了这个问题:
-我想在特定屏幕(1280x720)上进行可见的倒计时,但是如果我从以下代码中删除第10行,则导致第二个窗口打开: >
from future.moves import tkinter
top=tkinter.Tk()
HEIGHT=720
WIDTH=1280
canvas = tkinter.Canvas(top, height=HEIGHT, width=WIDTH)
canvas.pack()
class Tempo(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
self.label = tkinter.Label(top,width=10, font="Verdana 12 bold",bg="white")
self.label.place(relwidth=0.18,relheight=0.04,relx=0.5-0.09,rely=0.3-0.02)
self.remaining = 0
self.countdown(10)
def countdown(self, remaining = None):
if remaining is not None:
self.remaining = remaining
if self.remaining <= 0:
self.label.configure(text="time's up!")
else:
self.label.configure(text="%d" % self.remaining)
self.remaining = self.remaining - 1
self.after(1000, self.countdown)
tempo=Tempo()
tempo.countdown()
top.mainloop()
如何使其正常工作?