Python tkinter中,怎么做一个透明的悬浮窗口(无边框和标题栏)?

2024-12-02 05:07:57
推荐回答(1个)
回答1:

给你百度一个吧
import Tkinter
root = Tkinter.Tk()
root.overrideredirect(True)
#root.attributes("-alpha", 0.3)窗口透明度70 %
root.attributes("-alpha", 0.4)#窗口透明度60 %
root.geometry("300x200+10+10")
canvas = Tkinter.Canvas(root)
canvas.configure(width = 300)
canvas.configure(height = 200)
canvas.configure(bg = "blue")
canvas.configure(highlightthickness = 0)
canvas.pack()
x, y = 0, 0
def move(event):
global x,y
new_x = (event.x-x)+root.winfo_x()
new_y = (event.y-y)+root.winfo_y()
s = "300x200+" + str(new_x)+"+" + str(new_y)
root.geometry(s)
print("s = ",s)
print(root.winfo_x(),root.winfo_y())
print(event.x,event.y)
print()
def button_1(event):
global x,y
x,y = event.x,event.y
print("event.x, event.y = ",event.x,event.y)
canvas.bind("",move)
canvas.bind("",button_1)
root.mainloop()

#自己加个双击鼠标事件 关闭窗口 不然结束程序很不爽 要关闭IDE