0

While doing some activities to learn python/tkinter, I've faced this problem:

-I want to make a visible countdown in a specific screen (1280x720), but I can't make it work if I remove the 10th line from the following code, which is causing a second window to open:

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

How can I make it work properly?

The source from the code I'm using: Making a countdown timer with Python and Tkinter?

0 Answers0