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!
-
I have quickly looked through the API. Could you just call self.mouseX and self.mouseY ?Bridgekeeper– Bridgekeeper2015年11月17日 11:57:51 +00:00Commented Nov 17, 2015 at 11:57
-
i tried that its doesnt work.justin underland– justin underland2015年11月19日 06:48:04 +00:00Commented Nov 19, 2015 at 6:48
-
im not sure if i explained what im trying to do, i want the x, y coordinates, where ever my mouse hovers on the window that it createdjustin underland– justin underland2015年11月19日 06:49:09 +00:00Commented Nov 19, 2015 at 6:49
-
i also forgot to give you guys the manual for this library. mcsp.wartburg.edu/zelle/python/graphics/graphics.pdfjustin underland– justin underland2015年11月19日 06:52:31 +00:00Commented Nov 19, 2015 at 6:52
-
def refreshMouse(self): while True: if self.isClosed(): raise GraphicsError("getMouse in closed window") time.sleep(.1) # give up thread self.mouseX = None self.mouseY = None self.update() x,y = self.toWorld(self.mouseX, self.mouseY) return Point(x,y)justin underland– justin underland2015年11月19日 06:55:31 +00:00Commented Nov 19, 2015 at 6:55
1 Answer 1
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