Advertisement
famansour

MODIFIED WEBCODE# Draggabale windows work well

Sep 15th, 2020
1,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from tkinter import *
  2. root = Tk()
  3.  
  4. class WindowDraggable():
  5.  
  6.     def __init__(self, label):
  7.         self.label = label
  8.         label.bind('<ButtonPress-2>', self.StartMove)
  9.         label.bind('<ButtonRelease-2>', self.StopMove)
  10.         label.bind('<B2-Motion>', self.OnMotion)
  11.  
  12.     def StartMove(self, event):
  13.         self.x = event.x
  14.         self.y = event.y
  15.  
  16.     def StopMove(self, event):
  17.         self.x = None
  18.         self.y = None
  19.  
  20.     def OnMotion(self,event):
  21.         x = (event.x_root - self.x - self.label.winfo_rootx() + self.label.winfo_rootx())
  22.         y = (event.y_root - self.y - self.label.winfo_rooty() + self.label.winfo_rooty())
  23.         root.geometry("+%s+%s" % (x, y))
  24. # label = Label(root, text='drag me')
  25. label = root
  26. WindowDraggable(label)
  27. # label.pack()
  28. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement