Learn Python tkinter GUI drag & drop easy 👈

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024

ความคิดเห็น • 87

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +39

    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?

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

  • @ricks1129
    @ricks1129 2 ปีที่แล้ว +2

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

  • @Xatex18
    @Xatex18 ปีที่แล้ว +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!!!

  • @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.

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

    • @omairtech6711
      @omairtech6711 ปีที่แล้ว

      I still don't really understand it LOL.

    • @_call_me_sid_1457
      @_call_me_sid_1457 ปีที่แล้ว

      Could you pls explain me the algorithm...?

  • @monwil3296
    @monwil3296 4 ปีที่แล้ว +2

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

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks Mon Wil!

  • @blexbottt5119
    @blexbottt5119 ปีที่แล้ว +2

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

  • @thebuggser2752
    @thebuggser2752 3 ปีที่แล้ว +1

    Great presentation! Concise, clear and easy to follow.

  • @pastorjose9416
    @pastorjose9416 2 ปีที่แล้ว

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

  • @krishnamurari88
    @krishnamurari88 10 หลายเดือนก่อน +1

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

  • @jjbb84x
    @jjbb84x 3 ปีที่แล้ว +1

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

  • @LeeMinh2209
    @LeeMinh2209 8 หลายเดือนก่อน

    Please , do more video about python

  • @k.chriscaldwell4141
    @k.chriscaldwell4141 2 หลายเดือนก่อน

    Superb. Thank you.

  • @jhassee
    @jhassee ปีที่แล้ว

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

  • @derpfisti2457
    @derpfisti2457 ปีที่แล้ว +1

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

  • @razielrazielivich8861
    @razielrazielivich8861 3 ปีที่แล้ว

    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.

  • @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

  • @wingielee
    @wingielee 3 ปีที่แล้ว

    nice one bro...love it

  • @jersonmacapanas8958
    @jersonmacapanas8958 ปีที่แล้ว

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

  • @PersianRex
    @PersianRex ปีที่แล้ว +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน

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

    • @Frosturus
      @Frosturus 10 หลายเดือนก่อน

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

  • @alanrichter8594
    @alanrichter8594 2 ปีที่แล้ว

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

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

  • @innomindsco
    @innomindsco 3 ปีที่แล้ว

    i appreciate the briefing but like some details as well

  • @danylipsker
    @danylipsker 2 ปีที่แล้ว

    perfect tutorial. Thanks a lot sir

  • @im_the_raymond
    @im_the_raymond 2 ปีที่แล้ว

    Nice brooo

  • @abhishekdas2512
    @abhishekdas2512 4 ปีที่แล้ว

    Great 👍

  • @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?

  • @fentonmsu
    @fentonmsu 3 ปีที่แล้ว

    wonderfully explained

  • @videoseeker1101
    @videoseeker1101 ปีที่แล้ว

    Thank you for your help:)

  • @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?

  • @moradi13831
    @moradi13831 3 ปีที่แล้ว

    عالی

  • @johncammarata7064
    @johncammarata7064 2 ปีที่แล้ว

    Excellent! Thank you!

  • @DrWho2008t101
    @DrWho2008t101 3 ปีที่แล้ว

    Great Video!

  • @lw9954
    @lw9954 2 ปีที่แล้ว

    TY BRO

  • @lumberapple8820
    @lumberapple8820 3 ปีที่แล้ว

    Cool

  • @al3sha852
    @al3sha852 3 ปีที่แล้ว

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

  • @Henry_Nunez
    @Henry_Nunez 3 ปีที่แล้ว

    😊👍Excelente

  • @d1jn
    @d1jn 2 ปีที่แล้ว

    Thanks Bro, great tutorial!

  • @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

  • @bauerm85
    @bauerm85 3 ปีที่แล้ว

    thanks, that was even for me totally clear

  • @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 ??

  • @krzysiek1918
    @krzysiek1918 2 ปีที่แล้ว

    Thank you sooooooo much!!

  • @jirizbirkovsky6227
    @jirizbirkovsky6227 3 ปีที่แล้ว

    Thank You!

  • @dimitriosdesmos4699
    @dimitriosdesmos4699 4 ปีที่แล้ว

    very good

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks for watching Dimitrios

  • @beingzero7541
    @beingzero7541 2 ปีที่แล้ว

    Wow 💯%

  • @shahzodsayfiddinov9510
    @shahzodsayfiddinov9510 3 ปีที่แล้ว

    Thank you Bro!

  • @gustavoaponte1814
    @gustavoaponte1814 ปีที่แล้ว

    meow meow moew~!

  • @isaie9057
    @isaie9057 4 ปีที่แล้ว

    hello.my friend thank you !

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      thanks for watching Isaie!

  • @rabiagulcelik8732
    @rabiagulcelik8732 3 ปีที่แล้ว

    Thank you

  • @artura3553
    @artura3553 3 ปีที่แล้ว

    nice!

  • @mohamedsalman6558
    @mohamedsalman6558 2 ปีที่แล้ว

    think you

  • @hamzazad5258
    @hamzazad5258 5 หลายเดือนก่อน

    this one was difficult

  • @rogerdodger8813
    @rogerdodger8813 2 ปีที่แล้ว

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

    • @gianclgar
      @gianclgar 2 ปีที่แล้ว

      try C++ or Java

  • @rgbesmedia
    @rgbesmedia ปีที่แล้ว

    Buenísimo!

  • @bluenone
    @bluenone 4 ปีที่แล้ว

    2k 👏👏👏

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      We did it! 2k

  • @franciscodoberti5884
    @franciscodoberti5884 3 ปีที่แล้ว

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

  • @3dw3dw
    @3dw3dw 3 ปีที่แล้ว

    Bro...
    Thanks!

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +1

      thanks for watching 3dw

    • @3dw3dw
      @3dw3dw 3 ปีที่แล้ว

      @@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.

  • @drayemusic9548
    @drayemusic9548 3 ปีที่แล้ว

    Why isn't this code running 😭😭

  • @arpanshah355
    @arpanshah355 ปีที่แล้ว

    comment