Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- root = Tk()
- class WindowDraggable():
- def __init__(self, label):
- self.label = label
- label.bind('<ButtonPress-2>', self.StartMove)
- label.bind('<ButtonRelease-2>', self.StopMove)
- label.bind('<B2-Motion>', self.OnMotion)
- def StartMove(self, event):
- self.x = event.x
- self.y = event.y
- def StopMove(self, event):
- self.x = None
- self.y = None
- def OnMotion(self,event):
- x = (event.x_root - self.x - self.label.winfo_rootx() + self.label.winfo_rootx())
- y = (event.y_root - self.y - self.label.winfo_rooty() + self.label.winfo_rooty())
- root.geometry("+%s+%s" % (x, y))
- # label = Label(root, text='drag me')
- label = root
- WindowDraggable(label)
- # label.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement