Learn Python tkinter GUI drag & drop easy 👈

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 89

  • @BroCodez
    @BroCodez  4 роки тому +41

    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("",drag_start)
    label.bind("",drag_motion)
    label2.bind("",drag_start)
    label2.bind("",drag_motion)
    window.mainloop()

    • @anzhemeng8833
      @anzhemeng8833 3 роки тому

      Is it possible to confine the items in a certain area but they are still draggable?

    • @akaok2060
      @akaok2060 3 роки тому

      @@anzhemeng8833 maybe make you entire functions reliant on an if statement that checks if the event x/y parameters its trying to push (aka mouse action) are outside the bounds that you dont want them to be, that should work, right?

    • @sakshiharbhajanka2481
      @sakshiharbhajanka2481 3 роки тому

      can we make thew widgets drop to only the coordinates we want?

    • @JonibekHamroqulov-bf8gp
      @JonibekHamroqulov-bf8gp Рік тому

      I don't understand this x = widget.winfo_x() - widget.startX + event.x

    • @JonibekHamroqulov-bf8gp
      @JonibekHamroqulov-bf8gp Рік тому +1

      Can you explain this please?

  • @ricks1129
    @ricks1129 2 роки тому +2

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

  • @nssinquefield
    @nssinquefield 3 роки тому +5

    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!!

  • @lam8322
    @lam8322 3 роки тому +1

    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!

  • @Xatex18
    @Xatex18 2 роки тому +4

    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?

  • @juankorsia7909
    @juankorsia7909 2 роки тому +1

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

  • @pastorjose9416
    @pastorjose9416 2 роки тому

    Eu amo tkinter...
    Agora, a realidade pode ser o que eu quiser
    Muito obrigado, ajudou demais

  • @monwil3296
    @monwil3296 4 роки тому +2

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

  • @andrewpalmer1576
    @andrewpalmer1576 4 роки тому +3

    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.

  • @thebuggser2752
    @thebuggser2752 3 роки тому +1

    Great presentation! Concise, clear and easy to follow.

  • @jhassee
    @jhassee 2 роки тому

    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 UA-cam to put your content ahead of many others. Freecodecamp doesn't compare, I do however support their stuff as well.

  • @jjbb84x
    @jjbb84x 3 роки тому +1

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

  • @krishnamurari88
    @krishnamurari88 Рік тому +1

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

  • @derpfisti2457
    @derpfisti2457 2 роки тому +1

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

  • @jersonmacapanas8958
    @jersonmacapanas8958 Рік тому

    THIS IS AWESOME. can you also make the whole window move when the root.overrideredirect is 0.

  • @razielrazielivich8861
    @razielrazielivich8861 4 роки тому

    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.

  • @blexbottt5119
    @blexbottt5119 2 роки тому +2

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

  • @innomindsco
    @innomindsco 3 роки тому

    i appreciate the briefing but like some details as well

  • @k.chriscaldwell4141
    @k.chriscaldwell4141 4 місяці тому

    Superb. Thank you.

  • @im_the_raymond
    @im_the_raymond 3 роки тому

    Nice brooo

  • @danylipsker
    @danylipsker 3 роки тому

    perfect tutorial. Thanks a lot sir

  • @alfamari7675
    @alfamari7675 Рік тому

    How would I save the new coordinates of the moved widgets so that when I close and rerun the program the widgets would be in the location I moved them last?

  • @wingielee
    @wingielee 4 роки тому

    nice one bro...love it

  • @PersianRex
    @PersianRex 2 роки тому +2

    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. 🌹👍🏻

    • @omairtech6711
      @omairtech6711 Рік тому +1

      I am interested in an answer to this as well.

    • @MaxMustermann-y5m
      @MaxMustermann-y5m Рік тому

      i think it is so because you have to shift the label to the left to maintain its original position

    • @Frosturus
      @Frosturus Рік тому +1

      @@omairtech6711 This is very late, but i think this is the explanation,
      Everytime we move our mouse, we are creating a new coordinate, and our box is moving to that coordinate every time e.g
      (300,120) (2,49) (2,50) - My mouse moved down by 1 pixel
      so -> 120 - 49 + 50
      300 121 - This is the new coordinate the box will move to

    • @omairtech6711
      @omairtech6711 Рік тому

      @@Frosturus Thanks. I will watch the video again when ever I get time and then try to understand what you are saying.

    • @Frosturus
      @Frosturus Рік тому

      @@omairtech6711 ok cool! If you need me to explain it a different way, just let me know!

  • @alanrichter8594
    @alanrichter8594 3 роки тому

    Hi, i want to know if you can put collisions in the label(red and blue square for make them hit between itselfs)?

  • @d1jn
    @d1jn 2 роки тому

    Thanks Bro, great tutorial!

  • @LeeMinh2209
    @LeeMinh2209 10 місяців тому

    Please , do more video about python

  • @al3sha852
    @al3sha852 3 роки тому

    No need to be come a bro, thank you. But I appreciate the video all the same. Well done.

  • @johncammarata7064
    @johncammarata7064 2 роки тому

    Excellent! Thank you!

  • @kimayapanash8998
    @kimayapanash8998 3 роки тому +1

    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

  • @chariouibouchaib4416
    @chariouibouchaib4416 Рік тому

    Hello Sir. Thank you for the tutorial.
    Could you make a tutorial follows this which implement drag and drop reorder functionality in a list in tkinter?

  • @videoseeker1101
    @videoseeker1101 Рік тому

    Thank you for your help:)

  • @bauerm85
    @bauerm85 3 роки тому

    thanks, that was even for me totally clear

  • @aizenvermillion434
    @aizenvermillion434 3 роки тому +2

    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. :)

  • @DrWho2008t101
    @DrWho2008t101 4 роки тому

    Great Video!

  • @fentonmsu
    @fentonmsu 4 роки тому

    wonderfully explained

  • @sgurdmeal662
    @sgurdmeal662 2 місяці тому

    thank you king
    👑

  • @abhishekdas2512
    @abhishekdas2512 4 роки тому

    Great 👍

  • @lumberapple8820
    @lumberapple8820 3 роки тому

    Cool

  • @krzysiek1918
    @krzysiek1918 3 роки тому

    Thank you sooooooo much!!

  • @jirizbirkovsky6227
    @jirizbirkovsky6227 3 роки тому

    Thank You!

  • @hydarhydar2338
    @hydarhydar2338 Місяць тому

  • @moradi13831
    @moradi13831 3 роки тому

    عالی

  • @shahzodsayfiddinov9510
    @shahzodsayfiddinov9510 3 роки тому

    Thank you Bro!

  • @Henry_Nunez
    @Henry_Nunez 3 роки тому

    😊👍Excelente

  • @dimitriosdesmos4699
    @dimitriosdesmos4699 4 роки тому

    very good

    • @BroCodez
      @BroCodez  4 роки тому

      thanks for watching Dimitrios

  • @leopoldocouto
    @leopoldocouto 4 роки тому +1

    Is there any way to do the same without the window? Drag and drop it the screen

    • @BroCodez
      @BroCodez  4 роки тому +1

      That may be possible with the tkinter.dnd module.
      Thanks for question, that would be a good topic for a video

    • @leopoldocouto
      @leopoldocouto 4 роки тому

      @@BroCodez Would be great. ty

  • @beingzero7541
    @beingzero7541 2 роки тому

    Wow 💯%

  • @rabiagulcelik8732
    @rabiagulcelik8732 3 роки тому

    Thank you

  • @lw9954
    @lw9954 2 роки тому

    TY BRO

  • @rgbesmedia
    @rgbesmedia Рік тому

    Buenísimo!

  • @rogerdodger8813
    @rogerdodger8813 2 роки тому

    Is there any programs like Visual Basic i.e Drag and Drop. Python just has too much coding!

  • @isaie9057
    @isaie9057 4 роки тому

    hello.my friend thank you !

    • @BroCodez
      @BroCodez  4 роки тому

      thanks for watching Isaie!

  • @mohamedsalman6558
    @mohamedsalman6558 3 роки тому

    think you

  • @lam8322
    @lam8322 3 роки тому

    so is that true that we can create our own attribute for tkinter object ?? ( At 2:42 you said we can make our own attribute)
    But I guess it only works with tkinter right ??

  • @artura3553
    @artura3553 3 роки тому

    nice!

  • @3dw3dw
    @3dw3dw 4 роки тому

    Bro...
    Thanks!

    • @BroCodez
      @BroCodez  4 роки тому +1

      thanks for watching 3dw

    • @3dw3dw
      @3dw3dw 4 роки тому

      @@BroCodez no you dont understand how much you just helped me without all the bullshit I have to endure from others.
      It is my priviledge to subscribe to straight and useful content.

  • @bluenone
    @bluenone 4 роки тому

    2k 👏👏👏

  • @hamzazad5258
    @hamzazad5258 7 місяців тому

    this one was difficult

  • @gustavoaponte1814
    @gustavoaponte1814 Рік тому

    meow meow moew~!

  • @franciscodoberti5884
    @franciscodoberti5884 3 роки тому

    Hi! is there any way you can do it without importing Tkinter?

  • @drayemusic9548
    @drayemusic9548 3 роки тому

    Why isn't this code running 😭😭

  • @arpanshah355
    @arpanshah355 Рік тому

    comment