Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from time import strftime
- class Clock: ##Tkinter is best used as a class object. Makes life easier.
- def __init__(self):
- self.root = Tk()
- self.root.title("Clock")
- self.root.protocol("WM_DELETE_WINDOW", self.quitting) ## handle my own exit code.
- ##set position to be center of screen
- window_width = 1100
- window_height = 400
- ws = self.root.winfo_screenwidth() # width of the screen
- hs = self.root.winfo_screenheight() # height of the screen
- x = (ws/2)-(window_width/2)
- y = (hs/2)-(window_height/2)
- self.root.geometry("%sx%s+%s+%s" %(window_width, window_height, int(x), int(y)))
- ##
- # set window to pop up above others
- self.root.attributes("-topmost", True)
- self.root.attributes("-topmost", False)
- ##
- self.quit = False
- self.curtime = ""
- def update_time(self):
- self.curtime = strftime("%I:%M:%S")
- def run(self):
- display = Label(self.root, font="arial 200 bold", bg="blue violet", fg="lime green")
- display.pack(fill=BOTH, expand=1) # personal preference, i dont like grid()
- while not self.quit:
- self.update_time()
- display.configure(text=self.curtime)
- self.root.update()
- self.root.update_idletasks()
- def quitting(self):
- print("I clicked the X button. i can quit any running processes here.")
- self.quit=True
- if __name__ == "__main__":
- try:
- app = Clock()
- app.run()
- except Exception as err:
- print(err)
- print("quitting")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement