Reputation: 41
so im a beginner in programming, im taking my first programming course. and we a have a final project where we make a full program that does everything we learned. one of the things we learned is how to use libraries. but i want to make a simple game using the graphics.py(http://mcsp.wartburg.edu/zelle/python/graphics.py) beginner library. but it doesn't have a function that gets me the position of a mouse, every time the program refreshes.
so i need help with incorporating that into the graphics.py library, or tell me a very simple game library
i know there is a pygame library that i could use, but my instructor highly discourages it for beginners. unless there are other very simple game libraries out there, i cant really use them
any help would be appreciated
thank you!
Upvotes: 4
Views: 3782
Reputation: 354
Ok i had the time too look at the code now and do some quick tests.
If you look at your library, graphics are using tkinter. And since there are no function in the graphics.py that gives you your mouse position without needing a mouse click, you must bind your own event that updates your mouse position.
This is an example on how you can manage this, source:
win.bind('<Motion>', motion)
def motion(event):
x, y = event.x, event.y
print('{}, {}'.format(x, y))
Another suggestion is that your code inherits from the GraphWin class. This gives you instant access to all functions within that class. Though, inheritance, that is another question.
Best of luck
Upvotes: 6