I have my gui set up, and I am using a loop to set up output text to be displayed in the gui if the conditions are met. However, what handler do i use to display the text in the gui?
GUI Output Text
Collapse
X
-
You'll have to remind me: Tkinter or wxPython?Originally posted by wocoscI have my gui set up, and I am using a loop to set up output text to be displayed in the gui if the conditions are met. However, what handler do i use to display the text in the gui?
I think in Tk it'swhere self.text is a Tk.Text widget.Code:self.text.insert(text)
In wx it'swhere myTextCtrl is a multiline wx.TextCtrl.Code:self.myTextCtrl.AppendText(text)
-
Originally posted by bartoncYou'll have to remind me: Tkinter or wxPython?
I think in Tk it'swhere self.text is a Tk.Text widget.Code:self.text.insert(text)
In wx it'swhere myTextCtrl is a multiline wx.TextCtrl.Code:self.myTextCtrl.AppendText(text)
I am really just using Python v2.5 . I am not supposed to use other gui's. Really, we are just using the graphics .py file to make our gui.Comment
-
The only GUI that "comes with" python is Tkinter. Period. Tkinter has some graphics capability. Graphics packages generally don't make GUIs; GUIs generally can handle graphics.Originally posted by wocoscI am really just using Python v2.5 . I am not supposed to use other gui's. Really, we are just using the graphics .py file to make our gui.
Please show some work that you have done and we will get this straightened out.Comment
-
Here is the code. The Cases (1,2,3,4) has the text that needs to be displayed if the certain condition is met.
Code:from graphics import * def main(): win = GraphWin("BMI Calculator", 1200,700) win.setCoords(0.0, 0.0, 3.0, 4.0) ## Draw the interface Text(Point(1,3), " Height (inches):").draw(win) Text(Point(1,3.5), "Weight (lbs):").draw(win) Text(Point(1,1), "Body Mass Index:").draw(win) ht = Entry(Point(2,3), 5) ht.setText("0.0") ht.draw(win) wt = Entry(Point(2,3.5), 5) wt.setText("0.0") wt.draw(win) output = Text(Point(2,1),"") output.draw(win) suggestion = Text(Point(1,1),"") suggestion.draw(win) button = Text(Point(1.5,2.0),"Convert It") button.draw(win) Rectangle(Point(1,1.5), Point(2,2.5)).draw(win) ## Wait for a mouse click win.getMouse() ## Convert input ht = eval(ht.getText()) wt = eval(wt.getText()) bmi = wt * 703.0 / (ht * ht) ## Display output and change button output.setText("%0.1f" % bmi) button.setText("Quit") ## Wait for click and then quit win.getMouse() win.close() ## Case one n = 8 - bmi new = (18 * (ht * ht)) / 703.3 difference = new - wt x = difference * 2 if bmi < 16: ## figure out how to display the following text.. suggestion.setText("%0.1f","I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain", n ,"pounds over the next", x," weeks").draw(win) ## Case 2. elif bmi < 25: ## figure out how to display the following text.. output.setText("%0.1f", "Keep up the good work!" ## Case 3. elif bmi =< 30: ## figure out how to display the following text.. display the message "You could stand to lose weight. I'd like you to lose", n," pounds over the next", x," months." ## Case 4. elif bmi > 30: ## figure out how to display the following text.. display the message "We have a problem here. You need to lose", n," pounds over the next," x," months."Comment
-
The Text object methode that you are looking for is:Originally posted by bartoncThanks for posting the code.
I found the documentation here, but haven't found the download yet, so I can't play with it yet.
Anybody else ever heard of graphics.py (a thin wrapper for Tkinter) before?
setText(string)
Sets the text of the object to string.Comment
-
It turns out that Wartburg College has all the links for graphics.py.Originally posted by bartoncThanks for posting the code.
I found the documentation here, but haven't found the download yet, so I can't play with it yet.
Anybody else ever heard of graphics.py (a thin wrapper for Tkinter) before?Comment
-
Code:from graphics import * def main(): win = GraphWin("BMI Calculator", 1200,700) win.setCoords(0.0, 0.0, 3.0, 4.0) ## Draw the interface Text(Point(1,3), " Height (inches):").draw(win) Text(Point(1,3.5), "Weight (lbs):").draw(win) Text(Point(1,1), "Body Mass Index:").draw(win) ht = Entry(Point(2,3), 5) ht.setText("0.0") ht.draw(win) wt = Entry(Point(2,3.5), 5) wt.setText("0.0") wt.draw(win) output = Text(Point(2,1),"") output.draw(win) suggestion = Text(Point(1,1),"") suggestion.draw(win) button = Text(Point(1.5,2.0),"Convert It") button.draw(win) Rectangle(Point(1,1.5), Point(2,2.5)).draw(win) ## Wait for a mouse click win.getMouse() ## Convert input ht = eval(ht.getText()) wt = eval(wt.getText()) bmi = wt * 703.0 / (ht * ht) ## Display output and change button output.setText("%0.1f" % bmi) button.setText("Quit") ## Wait for click and then quit win.getMouse() win.close() ## Case one n = 8 - bmi new = (18 * (ht * ht)) / 703.3 difference = new - wt x = difference * 2 if bmi < 16: ## figure out how to display the following text.. 1 = "I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain", n ,"pounds over the next", x," weeks").draw(win) setText(1) ## Case 2. if bmi < 25: ## figure out how to display the following text.. output.setText("%0.1f", "Keep up the good work!" ## Case 3. if bmi =< 30: ## figure out how to display the following text.. display the message "You could stand to lose weight. I'd like you to lose", n," pounds over the next", x," months." ## Case 4. if bmi > 30: ## figure out how to display the following text.. display the message "We have a problem here. You need to lose", n," pounds over the next," x," months."
did I set case 1 up right?/??????Comment
-
Here are a couple of things that I see:
First: You need to use CODE tags! I'm the only one in this forum who can add them after you post, so nobody who is trying to get an answer for you can see the structure (or lack of it in this case) of your code.
Assign to a variable only and use string formats as before, as in:Code:## Case one n = 8 - bmi new = (18 * (ht * ht)) / 703.3 difference = new - wt x = difference * 2 if bmi < 16: ## figure out how to display the following text.. 1 = "I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain", n ,"pounds over the next", x," weeks")
message = "I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain %d pounds over the next %d weeks" %(n, x)
Then, after all the cases have run and decided what the value of message is:The proper syntax for "less than or equal" is <= not:Code:output.setText(message)
Code:## Case 3. if bmi =< 30:Comment
-
Originally posted by bartoncHere are a couple of things that I see:
First: You need to use CODE tags! I'm the only one in this forum who can add them after you post, so nobody who is trying to get an answer for you can see the structure (or lack of it in this case) of your code.
Assign to a variable only and use string formats as before, as in:Code:## Case one n = 8 - bmi new = (18 * (ht * ht)) / 703.3 difference = new - wt x = difference * 2 if bmi < 16: ## figure out how to display the following text.. 1 = "I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain", n ,"pounds over the next", x," weeks")
message = "I am ordering a work-up for eating disorders to be on the safe side. In the mean time,I would like you to gain %d pounds over the next %d weeks" %(n, x)
Then, after all the cases have run and decided what the value of message is:The proper syntax for "less than or equal" is <= not:Code:output.setText(message)
Code:## Case 3. if bmi =< 30:becomesCode:output.setText("%0.1f", "Keep up the good work!"Code:message = "%0.1f, Keep up the good work!" % bmi
Comment
-
Cases are written like this:Originally posted by bartoncbecomesCode:output.setText("%0.1f", "Keep up the good work!"Code:message = "%0.1f, Keep up the good work!" % bmi
Code:case = 1 if case == 1: print "one" elif case == 2: print "two" else: print "not a valid case"Comment
Comment