python - Tkinter 拖放标签信息到数据库
问题描述
我创建了一个简单的 GUI 来查看一个人坐在哪个座位上。名称标签可以拖放到不同的静态座位标签上。每次有人更换座位时,用户都可以将姓名标签拖放到不同的座位上。
我希望能够将该信息发送到数据库(无论是 excel 还是 sql 都可以),然后我可以稍后查看并找出谁坐在哪里等。我尝试过使用鼠标的坐标,但不够准确。有一个更好的方法吗?也许与widget.grid?
谢谢![在此处输入图片说明][1]
这是我的代码;
def label_maker(Seat_list,my_frame1, my_frame2):
run_lisst_title_label1 = Label(my_frame1,text = "Seat",compound='center',bd=2,relief=SUNKEN,bg=title_label_bgcolour,fg="white",font = font,width=12)
run_lisst_title_label1.place(x=7,y=50)
y_loco=90
x_loco=7
for item in Seat_list[0:25]:
run_label = Label(my_frame1,text = item,compound='center',bd=2,relief=SUNKEN,bg=seat_label_colour,fg="white",font = font,width=12)
run_label.place(x=x_loco,y=y_loco)
y_loco = y_loco + y_loco_plus
def drag_drop(name_list,my_frame2):
consist_list_title_label1 = Label(my_frame2,text = "Name",compound='center',bd=2,relief=SUNKEN,bg=title_label_bgcolour,fg="white",font = font,width=12)
consist_list_title_label1.place(x=7,y=50)
def drag_start(event):
widget = event.widget
widget.startX = event.x
widget.startY = event.y
def drag_motion(event):
widget = event.widget
x = widget.winfo_x() - widget.startX + event.x
y = widget.winfo_y() - widget.startY + event.y
widget.place(x=x//5*5, y=y//5*5)
y_loco=90
for item in name_list[0:25]:
x_loco=7
lrv_label = Label(my_frame2,text = item,compound='center',bd=1,relief=SUNKEN,bg=lrv_colour,fg="white",font = font )
lrv_label.place(x=x_loco,y=y_loco)
lrv_label.bind("<Button-1>",drag_start)
lrv_label.bind("<B1-Motion>",drag_motion)
y_loco = y_loco +y_loco_plus
y_loco=90
[enter image description here][1]
解决方案
推荐阅读
- c# - Nuget 包不会复制 .nuspec 中指定的 contentFiles
- javascript - 每列中的 DataTables 全局正则表达式搜索
- sql - 无法使用多行 SQL 代码调用过程.. 语法是什么?
- reactjs - 当我需要它通过反应导航发送它时,状态还没有准备好
- ajax - 如何创建 Ajax 过滤器以在 WordPress 中显示自定义帖子类型
- node.js - EventPattern 处理程序未在控制器外部触发
- makefile - Makefile - $< 用于多个规则
- pandas - 计算多维特征的皮尔逊系数
- excel - VBA 从 Excel 更新现有的 PPT 图表 - 内存过多?
- python - Python:在“。”中找不到“__main__”模块