Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Tkinter canvas draggable

def make_draggable(widget, btn="<Button-1>", motion="<B1-Motion>"):
    def __draggable__(widget):
        c.tag_bind(widget, btn, on_drag_start)
        c.tag_bind(widget, motion, on_drag_motion)
        c._item_id = widget # save the item ID for later use

    def on_drag_start(event):
        widget = event.widget
        # get the top-left coordinates of the selected item
        x, y, *_ = widget.bbox(widget._item_id)
        # save the offset of current mouse position from the top-left coordinates
        widget._dx = event.x - x
        widget._dy = event.y - y

    def on_drag_motion(event):
        widget = event.widget
        # calculate the top-left coordinates of the item that the item to be moved to
        x = event.x - widget._dx
        y = event.y - widget._dy
        # move the item using moveto() instead of move()
        widget.moveto(widget._item_id, x, y)

    __draggable__(widget)
Comment

PREVIOUS NEXT
Code Example
Python :: python requests cookies 
Python :: remove empty rows csv python 
Python :: format percentage python 
Python :: merge multiple csv files 
Python :: date to day python 
Python :: discord get user slash command 
Python :: dataframe row 
Python :: tkinter input box 
Python :: pandas replace zero with blank 
Python :: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 
Python :: display pythonpath linux 
Python :: get columns containing string 
Python :: binomial coefficient 
Python :: how to use prettytable with python 
Python :: check object attributes python 
Python :: how to check if a number is a perfect square python 
Python :: python get dict values as list 
Python :: pandas dataframe select last n columns 
Python :: how to make a radio in python 
Python :: how to only print final iteration of a for loop pyhton 
Python :: drop nulll python 
Python :: if keyboard.is_pressed 
Python :: sort list in python by substring 
Python :: initialize an array in python 
Python :: blank=True 
Python :: removing features pandas 
Python :: python smtp email 
Python :: df drop index 
Python :: use datetime python to get runtime 
Python :: install sklearn-features 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =