'Is there a way to create a mouse-down drag event using Zelle's graphics module?
Using Zelle Graphics.py - is there a way to create a mouse-down draggable event? I have an easy way to create points, but cannot get them to continue to draw as the mouse is dragged or while the button is pressed. I am pretty sure that tkinter has a way of doing this, but I am unsure of how to incorporate that into this code. Does graphics.py have a method?
from graphics import *
win = GraphWin("drag", 500, 500)
win.master.attributes('-topmost', True)
point1 = Point(250, 250)
point1.draw(win)
while True:
coord = win.checkMouse()
if coord == None:
pass
else:
point1 = Point(coord.getX(), coord.getY())
point1.setFill("red")
point1.draw(win)
win.mainloop()
Solution 1:[1]
I tried it with tkinter bindings and came up with this solution. Now I am looking for a way to include a game loop in the mix.
from graphics import *
win = GraphWin("drag", 500, 500)
win.master.attributes('-topmost', True)
point1 = Point(250, 250)
point1.draw(win)
def motion(event):
x1, y1 = event.x, event.y
point1 = Point(x1, y1)
point1.setFill("red")
point1.draw(win)
win.bind('<B1-Motion>', motion)
win.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | netrate |
