python: AI生成,标签拖拽

import tkinter as tk
 
def on_drag_start(event):
    widget.lift()  # Colocar o widget no topo quando arrastado
    widget.start_x = event.x
    widget.start_y = event.y
	

	
def on_drag_motion(event):
    x = widget.winfo_x() - widget.start_x + event.x
    y = widget.winfo_y() - widget.start_y + event.y
    widget.place(x=50, y=50)

	
def on_drag_start_new(event):
	
    
    widget_new.lift()
    widget_new.start_x = event.x
    widget_new.start_y = event.y
	
def on_drag_motion_new(event):

    x = widget_new.winfo_x() - widget_new.start_x + event.x
    y = widget_new.winfo_y() - widget_new.start_y + event.y
    widget_new.place(x=x, y=y) 
	
def create_draggable_widget():
    global widget
    global widget_new	

    root = tk.Tk()
    widget = tk.Label(root, text="test", bg="lightblue")
    widget.bind("<ButtonPress-1>", on_drag_start)
    widget.bind("<B1-Motion>", on_drag_motion)
    widget.place(x=50, y=50, anchor="nw")
	
    widget_new = tk.Label(root, text="test", bg="lightblue")
    widget_new.bind("<ButtonPress-1>", on_drag_start_new)
    widget_new.bind("<B1-Motion>", on_drag_motion_new)
    widget_new.place(x=50, y=50, anchor="nw")
	
    root.mainloop()
 
create_draggable_widget()

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值