Skip to content

Instantly share code, notes, and snippets.

@limitedeternity
Last active January 10, 2019 11:07
Show Gist options
  • Save limitedeternity/5667acd77c35ae387cf830dd815f22e3 to your computer and use it in GitHub Desktop.
Save limitedeternity/5667acd77c35ae387cf830dd815f22e3 to your computer and use it in GitHub Desktop.
Tkinter time display widget
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