使用tkinter 编写一个可以拖动的时钟[]~( ̄▽ ̄)~*
¶import tkinter import threading import datetime import time app = tkinter.Tk() app.overrideredirect(True) #不显示标题栏 app.attributes(’-alpha’, 0.9) #半透明 app.attributes(’-topmost’, 1) #总是在顶端 app.geometry(‘110x25+100+100’) #初始大小与位置 labelDateTime = tkinter.Label(app) labelDateTime.pack(fill=tkinter.BOTH, expand=tkinter.YES) labelDateTime.configure(bg = ‘gray’) X = tkinter.IntVar(value=0) #记录鼠标左键按下的位置 Y = tkinter.IntVar(value=0) canMove = tkinter.IntVar(value=0) #窗口是否可拖动 still = tkinter.IntVar(value=1) #是否仍在运行 def onLeftButtonDown(event): app.attributes(’-alpha’, 0.4) #开始拖动时增加透明度 X.set(event.x) #鼠标左键按下,记录当前位置 Y.set(event.y) canMove.set(1) #并标记窗口可拖动 labelDateTime.bind(’
Hobby lead creation, technology change world.
- Post link: 209.html
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.