Skip to content

Instantly share code, notes, and snippets.

@1f0
Created February 10, 2019 14:29
Show Gist options
  • Save 1f0/279506c8cec4433d2af8ea3b517d7e54 to your computer and use it in GitHub Desktop.
Save 1f0/279506c8cec4433d2af8ea3b517d7e54 to your computer and use it in GitHub Desktop.
A simple clock under windows os, using python library 'keyboard' to detect hot-key.
import keyboard
import time
from tkinter import *
class Clock(Tk):
def __init__(self, master=None):
Tk.__init__(self, master)
self.wm_attributes("-topmost", 1)
self.createWidgets()
def tick(self):
newTime = time.strftime('%H:%M:%S')
if newTime != self.time:
self.time = newTime
self.timeLabel.config(text=self.time)
self.timeLabel.after(500, self.tick)
def createWidgets(self):
self.time = ''
self.timeLabel = Label(self, font=('times', 20, 'bold'))
self.timeLabel.pack()
self.tick()
clock = None
def invokeClock():
global clock
print('invoke:', id(clock))
if clock == None:
clock = Clock()
keyboard.add_hotkey('ctrl+alt+k', invokeClock)
keyboard.wait()
@1f0
Copy link
Author

1f0 commented Jun 26, 2019

in linux python2.7, tkinter should be Tkinter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment