Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 28th, 2012, 10:17 AM
 Chrianna286
Registered User

Join Date: Nov 2012
Posts: 9
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
How to start this while loop

hey! So i have a python graphics program and im stuck and how to do the next part.

If anyone could show me how to start it i would appreciate it a lot. Thanks.

• Write a graphics program that simulates a calculator.
• The window that the user sees must have a label and an area for the first operand, the second operand, and the result.
• The default values for the two operands need to be 0.
• 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.

from graphics import *

def main():
#Create graphics window
win = GraphWin("Mathemathics", 400, 400)

#Make the background grey
win.setBackground("grey")

#Set Coordinates
win.setCoords(0, 0, 90, 100)

r1 = Rectangle(Point(5,5), Point(20,20))
r1.draw(win)

r2 = r1.clone()
r2.move(20,0)
r2.draw(win)

r3 = r1.clone()
r3.move(40,0)
r3.draw(win)

r4 = r1.clone()
r4.move(60,0)
r4.draw(win)

Text(Point(12.5,12.5), "+").draw(win)
Text(Point(32,12.5), "-").draw(win)
Text(Point(52,12), "*").draw(win)
Text(Point(72,12.5), "/").draw(win)

Text(Point(15,80), "First Number:").draw(win)
e1 = Entry(Point(20,75), 8)
e1.draw(win)

Text(Point(15,60), "Second Number:").draw(win)
e2 = Entry(Point(20,55), 8)
e2.draw(win)

win.getMouse()
win.close()
main()

#2
November 28th, 2012, 12:21 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,153
Time spent in forums: 1 Month 3 Weeks 2 Days 8 h 27 m 2 sec
Reputation Power: 455
I'm not particularly interested to support nonstandard python. The graphics module isn't part of the python distribution.
At
http://www.manning.com/grayson/
File 1 (2.79 Mb) -- All of the source code for the examples
Chapter 03 has gui tkinter calculator.
__________________
[code]Code tags[/code] are essential for python code!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > How to start this while loop