Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2012, 10:42 AM
Chrianna286 Chrianna286 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Chrianna286 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
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 *

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)


Text(Point(50,60), "Answer:").draw(win)


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

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..

Reply With Quote
  #2  
Old November 28th, 2012, 10:53 AM
rrashkin's Avatar
rrashkin rrashkin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Location: 39N 104.28W
Posts: 90 rrashkin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 37 m 44 sec
Reputation Power: 2
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?

Reply With Quote
  #3  
Old November 28th, 2012, 12:02 PM
Chrianna286 Chrianna286 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Chrianna286 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old November 28th, 2012, 12:28 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
tkinter.mainloop() handles this problem.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #5  
Old November 28th, 2012, 12:34 PM
Chrianna286 Chrianna286 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Chrianna286 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
i would use that but i cant... i have to use the rectangles

Reply With Quote
  #6  
Old November 28th, 2012, 12:51 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
The graphics module is here, and it's based on tkinter, so you really could use
tk.Button(_root,text='click me',command=my_callback_function)
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 12:52 PM. Reason: fix my brackets!

Reply With Quote
  #7  
Old November 28th, 2012, 12:57 PM
Chrianna286 Chrianna286 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Chrianna286 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
okay thanks for the help

Reply With Quote
  #8  
Old November 28th, 2012, 01:02 PM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 291 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 19 m 46 sec
Reputation Power: 6
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
Quote:
"getMouse() Pauses for the user to click a mouse in the window and returns where the mouse was clicked as a Point object."

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 01:14 PM.

Reply With Quote
  #9  
Old November 28th, 2012, 01:13 PM
Chrianna286 Chrianna286 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 Chrianna286 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 52 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Im Stuck In Python

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap