在具有自定义标题栏的同时移动 window,它不会捕捉到光标的角
Move the window while having a custom title bar and it not snapping to the corner of the cursor
任何人都可以帮我弄清楚如何移动 window 并且它在使用自定义标题栏时不会吸附到角落...
from tkinter import *
root = Tk()
root.geometry('571x819')
root.overrideredirect(1)
root.wm_attributes("-transparentcolor", "grey")
def move_app(e):
root.geometry(f'+{e.x_root}+{e.y_root}')
frame_photo = PhotoImage(file = 'F:\gui\Frame 1.png')
frame_label = Label(root, borderwidth = 0, bg = 'grey', image = frame_photo)
frame_label.pack(fill=BOTH, expand = True)
title_bar = Frame(root, bg='#FFF6C9', relief='raised', bd=0,highlightthickness=0)
title_bar_title = Label(title_bar, bg='#FFF6C9',bd=0,fg='white',font=("helvetica",
10),highlightthickness=0)
frame_label.bind("<B1-Motion>", move_app)
root.mainloop()
可以通过绑定<Button-1>
事件保存开始移动时window角top-left的偏移量,然后计算top-left角的位置window 基于 move_app()
内的这个偏移量:
def start_drag(e):
# save the offset from the top-left corner of window
e.widget.offset = (e.x, e.y)
def move_app(e):
# calculate the top-left corner of window based on the saved offset
root.geometry(f'+{e.x_root-e.widget.offset[0]}+{e.y_root-e.widget.offset[1]}')
...
frame_label.bind("<Button-1>", start_drag)
frame_label.bind("<B1-Motion>", move_app)
...
任何人都可以帮我弄清楚如何移动 window 并且它在使用自定义标题栏时不会吸附到角落...
from tkinter import *
root = Tk()
root.geometry('571x819')
root.overrideredirect(1)
root.wm_attributes("-transparentcolor", "grey")
def move_app(e):
root.geometry(f'+{e.x_root}+{e.y_root}')
frame_photo = PhotoImage(file = 'F:\gui\Frame 1.png')
frame_label = Label(root, borderwidth = 0, bg = 'grey', image = frame_photo)
frame_label.pack(fill=BOTH, expand = True)
title_bar = Frame(root, bg='#FFF6C9', relief='raised', bd=0,highlightthickness=0)
title_bar_title = Label(title_bar, bg='#FFF6C9',bd=0,fg='white',font=("helvetica",
10),highlightthickness=0)
frame_label.bind("<B1-Motion>", move_app)
root.mainloop()
可以通过绑定<Button-1>
事件保存开始移动时window角top-left的偏移量,然后计算top-left角的位置window 基于 move_app()
内的这个偏移量:
def start_drag(e):
# save the offset from the top-left corner of window
e.widget.offset = (e.x, e.y)
def move_app(e):
# calculate the top-left corner of window based on the saved offset
root.geometry(f'+{e.x_root-e.widget.offset[0]}+{e.y_root-e.widget.offset[1]}')
...
frame_label.bind("<Button-1>", start_drag)
frame_label.bind("<B1-Motion>", move_app)
...