Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f33a34b

Browse files
authoredJan 1, 2020
Add files via upload
1 parent 6e42c29 commit f33a34b

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
 

‎Time Percentage.pyw

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from tkinter import *
2+
from threading import Timer
3+
from datetime import datetime
4+
5+
x, y = 1700, 15
6+
7+
WIDTH, HEIGHT = 100, 40
8+
9+
root = Tk()
10+
root.overrideredirect(True)
11+
root.resizable(False, False)
12+
root.geometry('%dx%d+%d+%d' % (WIDTH, HEIGHT, x, y))
13+
14+
# movement code adapted from:
15+
# https://stackoverflow.com/questions/4055267/tkinter-mouse-drag-a-window-without-borders-eg-overridedirect1
16+
17+
locked = False
18+
19+
def mouse_motion(event):
20+
if not locked:
21+
global x, y
22+
offset_x, offset_y = event.x - x, event.y - y
23+
new_x = root.winfo_x() + offset_x
24+
new_y = root.winfo_y() + offset_y
25+
root.geometry(f"+{new_x}+{new_y}")
26+
27+
def left_click(event):
28+
if not locked:
29+
global x, y
30+
x, y = event.x, event.y
31+
32+
def middle_click(event):
33+
if not locked:
34+
root.destroy()
35+
36+
def right_click(event):
37+
global locked
38+
locked = not locked
39+
40+
root.bind("<B1-Motion>", mouse_motion)
41+
root.bind("<Button-1>", left_click)
42+
root.bind("<Button-2>", middle_click)
43+
root.bind("<Button-3>", right_click)
44+
45+
# End of Movement Code
46+
47+
text = StringVar()
48+
49+
l = Label(root, textvariable=text, bg="#333333", fg='#cccccc', font=('Verdana', 16))
50+
l.pack(fill=BOTH, expand=True)
51+
52+
def update():
53+
now = datetime.now()
54+
seconds = (now - now.replace(hour=0, minute=0, second=0, microsecond=0)).seconds
55+
56+
text.set(str(format(round(seconds/864, 2), '.2f')) + '%')
57+
58+
t = Timer(1, update)
59+
t.setDaemon(True)
60+
t.start()
61+
62+
update()
63+
root.mainloop()

0 commit comments

Comments
 (0)
Please sign in to comment.