1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| import tkinter as tk import time from datetime import datetime
root = tk.Tk()
winWidth = 560 winHeight = 160
screenWidth = root.winfo_screenwidth() screenHeight = root.winfo_screenheight()
x = int((screenWidth - winWidth) / 2) y = int((screenHeight - winHeight) / 2)
root.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
var = tk.StringVar() var2 = tk.StringVar()
def gettime(): var.set(time.strftime("%Y-%m-%d %X")) root.after(1000, gettime)
def week(): week_list = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] a = week_list[datetime.now().weekday()] return a
var.set(gettime()) var2.set(week())
w1 = tk.Label(root, textvariable=var, font=("微软雅黑", 40),width=16,height=1) w1.place(x=0,y=0) w2 = tk.Label(root, textvariable=var2, font=("微软雅黑", 40),width=5,height=1) w2.place(x=0,y=1)
w1.pack() w2.pack()
root.overrideredirect(1) root.wm_attributes("-alpha", 0.5) root.wm_attributes("-toolwindow", True) root.wm_attributes("-topmost", True)
def myquit(*args): root.destroy()
root.bind("<Any-KeyPress>", myquit)
def StartMove(event): global x, y x = event.x y = event.y
def StopMove(event): global x, y x = None y = None
def OnMotion(event): global x, y deltax = event.x - x deltay = event.y - y root.geometry("+%s+%s" % (root.winfo_x() + deltax, root.winfo_y() + deltay)) root.update() print(event.x, event.y, root.winfo_x(), root.winfo_y(), root.winfo_width(), root.winfo_height())
root.bind("<ButtonPress-1>", StartMove) root.bind("<ButtonRelease-1>", StopMove) root.bind("<B1-Motion>", OnMotion)
root.mainloop()
|