import tkinter as tk
# select a color as the transparent color
TRNAS_COLOR = '#abcdef'
root = tk.Tk()
root.overrideredirect(1)
root.attributes('-transparentcolor', TRNAS_COLOR)
image = tk.PhotoImage(file='/path/to/image.png')
tk.Label(root, image=image, bg=TRNAS_COLOR).pack()
# support dragging window
def start_drag(event):
global dx, dy
dx, dy = event.x, event.y
def drag_window(event):
root.geometry(f'+{event.x_root-dx}+{event.y_root-dy}')
root.bind('<Button-1>', start_drag)
root.bind('<B1-Motion>', drag_window)
root.mainloop()
您可以使用透明PNG图像创建透明窗口,如下所示:
然后可以使用
root.geometry(...)
移动根窗口相关问题 更多 >
编程相关推荐