Learn Python tkinter GUI drag & drop easy 👈

preview_player
Показать описание
Python drag & drop GUI tkinter tutorial for beginners

#Python #drag #drop #GUI #tkinter #tutorial #beginners
Рекомендации по теме
Комментарии
Автор

from tkinter import *

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, y=y)

window = Tk()

label = Label(window, bg="red", width=10, height=5)
label.place(x=0, y=0)

label2 = Label(window, bg="blue", width=10, height=5)
label2.place(x=100, y=100)

label.bind("<Button-1>", drag_start)
label.bind("<B1-Motion>", drag_motion)

label2.bind("<Button-1>", drag_start)
label2.bind("<B1-Motion>", drag_motion)

window.mainloop()

BroCodez
Автор

OK, this is an amazing intro to building a drag-and-drop GUI in Python. I can't believe how EASY it looks! Thank you for posting this!!

nssinquefield
Автор

Question: I get an AttributeNotExist -sort of error for label.startX and label.startY. I coulnd^t find any hints towards them in the documentation. What are the correct (new) names of these now?

Xatex
Автор

Superb explanation. I am taking up coding after a gap of 11 years and these tutorials are of extreme help.

ricks
Автор

I got a problem whhere unresolved attribute reference 'startX' for class 'Label' bro, python 3.10 ver here help me

blexbottt
Автор

Excellent training session. Thank you.
P.S. May want to make this a series on DnD. Next maybe Dragging from a menu bar and Dropping in the work area.

andrewpalmer
Автор

Bro! Thank you so much! Great tutorial! Simple, easy clean, easy to follow with no extra fluff! SUBSCRIBED!

jjbbx
Автор

Explanation very good with a lot of details. Kudos!!!

juankorsia
Автор

I took 5 min to understard the algorithm you use to drag and drop. It relates to vectors which I love at mathematic. Thanks you for teaching!

lam
Автор

Eu amo tkinter...

Agora, a realidade pode ser o que eu quiser

Muito obrigado, ajudou demais

pastorjose
Автор

Bro, again you made Python the best alternative for any new programmer. 😎👏

monwil
Автор

Great presentation! Concise, clear and easy to follow.

thebuggser
Автор

Sir I have questions.
How to change only selected label size use of mouse if you have multiple label please reply

krishnamurari
Автор

I'm such a fan now, I truly hope you make a school of programming so I can throw my money at you. My own ambition at 36 years old is to become as dangerous as possible when it comes to programming. I comment some nonsense here, but that is purely to get Youtube to put your content ahead of many others. Freecodecamp doesn't compare, I do however support their stuff as well.

jhassee
Автор

Umm... Excuse me, I'd like to ask what maybe the problem with my tkinter as I tried the code here but it made an Exception error and says that 'widget' is not defined once I tried to drag either labels. I checked both the code in the video and the code here in the comment and found nothing in mine that is any different. I do hope you'd be able to find this and help me. Thank you very much. :)

aizenvermillion
Автор

Hi.
Thank you so much for creating python tutorials bro. ❤️
I have a question though.
Why it's necessary subtract label.start from label.winfo?
I mean we can do "drag and drop" without writing this. Can't we?
Thank you in advance. 😍
Cheers. 🌹👍🏻

PersianRex
Автор

Thank you so much for your lesson. You explained it very clearly and in detail. Revealing your motives for writing code. I wish you good health and creative success.

razielrazielivich
Автор

Perhaps the title is a little misleading
I was expecting drag and drop from a palette into a frame
That kind of drag and drop

kimayapanash
Автор

i appreciate the briefing but like some details as well

innomindsco
Автор

step 3 = done
step 1 = done 👍
step 2 = done 🗯
thank you very much Bro!

derpfisti