November 28th, 2012, 11:42 AM
Im Stuck In Python
i need help asap or some feedback!!
I have no idea how to go on.. im stuck
I have to write a graphics program that simulates a calculator. Which ive already done. The window that the user sees must have a label and an area for the first operand, the second operand, and the result. The user needs to be able to choose whether to add, subtract, multiply, and divide the operands to produce the result by clicking on the appropriate button. The operation will only occur when the user clicks in the box labeled with that operation.The result will be updated as long as the user continues to choose an operation. The result will be displayed to two decimal point accuracy.
I already have this much..
from graphics import *
#Create graphics window
win = GraphWin("Mathemathics", 400, 400)
#Make the background grey
win.setCoords(0, 0, 90, 100)
r1 = Rectangle(Point(5,5), Point(20,20))
r2 = r1.clone()
r3 = r1.clone()
r4 = r1.clone()
Text(Point(15,80), "First Number:").draw(win)
e1 = Entry(Point(20,75), 8)
Text(Point(15,60), "Second Number:").draw(win)
e2 = Entry(Point(20,55), 8)
How would I make a while loop so that when the user clicks between the points of the add rectantgle that it adds the two entry numbers..? and etc..
November 28th, 2012, 11:53 AM
I'm not at all familiar with any module named "graphics" so I can't really help you with any specifics (now, Tkinter or pyGTK would be another kettle of horses of a different color).
That said, let's imagine that when the user clicks anywhere on the window, "win", an event is generated. You don't have any "listeners" created so I'm guessing the "GraphWin" constructor takes care of that. Even so, when the click event happens, there should be some attributes associated with pointer position that can be accessed. They would be like %x and %y or something. You would want to check if %x is between 5 and 20 AND if %y is between 5 and 20 (based on what I infer are the coordinates of the "add" or "+" rectangle: r1 = Rectangle(Point(5,5), Point(20,20)).
My question to you is why do you think you want to use a while loop here?
November 28th, 2012, 01:02 PM
I want to do a while loop because i want the user to be able to click add, subtract, multipy, or divide as many times as they want until they click exit. Do you know how to do that?
November 28th, 2012, 01:28 PM
November 28th, 2012, 01:34 PM
i would use that but i cant... i have to use the rectangles
November 28th, 2012, 01:51 PM
The graphics module is here, and it's based on tkinter, so you really could use
and _root.update() or _root.mainloop()
but thanks, like rrashkin, I'm not going to support the graphics module.
Last edited by b49P23TIvg; November 28th, 2012 at 01:52 PM.
Reason: fix my brackets!
[/code] are essential for python code and Makefiles!
November 28th, 2012, 01:57 PM
November 28th, 2012, 02:02 PM
I would guess that the name "getMouse()" was chosen for a reason. The docs for the Graphics module (I Googled "graphics module documentation") say this
You would then have to get the x and y values from the Point object (i.e. an instance of the Point class), how you do this should also be in the docs, and then test for if/which rectangle the mouse was in.
Last edited by dwblas; November 28th, 2012 at 02:14 PM.
November 28th, 2012, 02:13 PM
I understand what i have to do. I just cant figure out how to put it in Code form is what i need help with