Monday, 2024-04-29, 5:02 PM
Welcome Guest

Distance Education

[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Christos  
Forum » Software Development » RE:Work » Python GUI help (using the :get()" function.)
Python GUI help
jonoDate: Thursday, 2009-07-30, 8:47 AM | Message # 1
Sergeant
Group: Checked
Messages: 24
Awards: 0
Reputation: 0
Status: Offline
i've been trying this weeks python activity but am unable to get it to work. This is wat i have done so far;
Code


from Tkinter import *

class Product(Frame):
         def __init__(self,master):
                 frame = Frame(master)
                 Frame.__init__(self, master)
                 self.grid()
                 self.create_widgets()
            
             
         def create_widgets(self):
                 self.Text1 = Text(self, width=11, height=2, wrap=WORD)
                 self.Text1.grid(row = 0, column = 0, columnspan = 1, sticky = W)

                 self.Text2 = Text(self, width=11, height=2, wrap=WORD)
                 self.Text2.grid(row = 1, column = 0, columnspan = 1, sticky = W)

                 self.Text3 = Text(self, width=11, height=2, wrap=WORD)
                 self.Text3.grid(row = 3, column = 0, columnspan = 1, sticky = W)

                 self.btncalc = Button(self, text="Calculate Product", command=self.Calc)
                 self.btncalc.grid(row = 2, column = 0, columnspan = 1, sticky = W)

                  
         def Calc(self):
                 value1 = self.Text1.get()
                 value2 = self.Text2.get()
                 totalvalue = (value1 + value2)
                 self.Text3.insert(0.0, totalvalue)
                  
                            

root = Tk()
root.title("Product Calculator")
root.geometry("100x150")
app = Product(root)
root.mainloop()
[code]


Can you be the one to judge it all?
 
Dr4c0niusDate: Thursday, 2009-07-30, 1:34 PM | Message # 2
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
Just finished mine, ill have a look at your and see if I can get it working

Edit:

Ok, you've got a few things wrong in the Product.Calc() method. The get command for text boxes needs a location to get, you give it get(1.0, END) to get the whole lot.

Once thats fixed you'll need to change the values obtained with get into integers so that python can add them properly.

Hope that helps biggrin


Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

Message edited by Dr4c0nius - Thursday, 2009-07-30, 1:47 PM
 
jonoDate: Friday, 2009-07-31, 3:49 AM | Message # 3
Sergeant
Group: Checked
Messages: 24
Awards: 0
Reputation: 0
Status: Offline
thanx A LOT, i had 3 IT teachers all looking for a solution but they couldn't find it lol.

Can you be the one to judge it all?
 
Dr4c0niusDate: Friday, 2009-07-31, 4:40 PM | Message # 4
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
Lol, any time. Did the teachers actually know python? tongue

Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

 
HaydenJohnsDate: Saturday, 2009-08-01, 8:46 AM | Message # 5
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
I'm a bit behind on the python and haven't done this weeks activity for it - I didn't have net/computer access for a few days, and missed all of my software periods this week. I was stuck at a theater doing our schools production.

Added (2009-08-01, 8:46 Am)
---------------------------------------------
Just a heads up, didn't it say that we needed to make it save the result to a file (assuming that you haven't added the function to the code)?

Quote
* Create a GUI with two text entry boxes in which numbers can be entered
* Create a third text box in which the product of the two numbers can be displayed.
* Add a button to perform a multiplication of the numbers entered in the first two text boxes so that it is displayed in the third text box.
* Add a save button which saves and appends the contents of the third text box to a file.


~ Click it
 
Forum » Software Development » RE:Work » Python GUI help (using the :get()" function.)
  • Page 1 of 1
  • 1
Search: