Basic Timer In Tkinter
I have written some code for a python timer but when ever I run it I get an error but the thing is I don't know what to do so I came here for help after I searched all over the int
Solution 1:
You have to initiate global sec
in start.ie:
......
# Timer Startdef start():
global sec
.....
you can put inside it in a class
. so that you don't have to worry about the scope of variables..
from tkinter import *
import time
classApp():
def__init__(self):
self.window = Tk()
self.root = Frame(self.window, height=200,width=200)
self.root.pack()
self.root.pack_propagate(0)
self.window.title('Timer')
self.label = Label(text="")
self.label.pack()
self.sec = 0
self.timerupdate()
self.root.mainloop()
deftimerupdate(self):
self.sec = self.sec + 1
self.label.configure(text=self.sec)
self.root.after(1000, self.timerupdate)
app=App()
app.mainloop()
Post a Comment for "Basic Timer In Tkinter"