简体   繁体   中英

mouse input with graphics.py

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM