Last active
January 10, 2019 11:07
-
-
Save limitedeternity/5667acd77c35ae387cf830dd815f22e3 to your computer and use it in GitHub Desktop.
Tkinter time display widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tkinter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import Tk, Label, StringVar | |
from datetime import datetime | |
from os import fork | |
from sys import exit | |
class TimeDisplay: | |
def __init__(self): | |
self.window = Tk() | |
self.window.title('Current Time') | |
self.window.resizable(False, False) | |
self.currentTime = StringVar() | |
self.getTime() | |
label = Label(self.window, height=5, width=20, textvariable=self.currentTime) | |
label.config(font=('Verdana', 20, 'bold')) | |
label.pack() | |
try: | |
self.window.mainloop() | |
except KeyboardInterrupt: | |
self.window.quit() | |
def getTime(self): | |
self.currentTime.set(datetime.now().strftime('%d-%m-%Y %H:%M:%S')) | |
self.window.after(100, self.getTime) | |
if __name__ == "__main__": | |
if fork(): | |
print('Detaching process...') | |
exit() | |
TimeDisplay() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment