Drag and drop multiple objects using python tkinter. #shorts #coding #python #tkinter

preview_player
Показать описание

In this video I showed you how to drag and drop multiple objects using python and a library called tkinter. If you want more content with the tkinter you can drop a like! I hope I helped you!
You can hit that subscribe button because at 100 subscribers I will do a live stream with all the basics of C++!!! You shouldn't miss it!
Рекомендации по теме
Комментарии
Автор

Exactly what i was looking for. Thank you very much!

terae
Автор


The code:
from tkinter import *
def drag_pos(event):
Object=event.widget
Object.startX=event.x
Object.startY=event.y
def drag(event):
Object=event.widget
x=Object.winfo_x() - Object.startX+event.x
y=Object.winfo_y() - Object.startY+event.y
Object.place(x=x, y=y)
window =Tk()
window.geometry("720x520")
square = Label(window, bg="blue", width=10, height=5)
square.place(x=0, y=0)
square2 = Label(window, bg="red", width=10, height=5)
square2.place(x=100, y=100)
square3 = Label(window, bg="green", width=10, height=5)
square3.place(x=150, y=300)
square2.bind("<Button-1>", drag_pos)
square2.bind("<B1-Motion>", drag)
square.bind("<Button-1>", drag_pos)
square.bind("<B1-Motion>", drag)
square3.bind("<Button-1>", drag_pos)
square3.bind("<B1-Motion>", drag)
window.mainloop()

Boolcoder
welcome to shbcf.ru