2 Replies - 598 Views - Last Post: 21 March 2015 - 02:12 PM Rate Topic: -----

#1 Moon_Serenity   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-March 15

Problem with the get() function on GUI/Tkinter

Posted 21 March 2015 - 01:08 PM

The purpose of this code is to edit a questionnaire for a user but for now while I did manage to make a nice frame and GUI interface, the get() function is actually empty when I click it. So need help on seeing what I did wrong since I jus started learning Python (or any programing languages)


from tkinter import *
#from Personality import Question1

#Font size and style
FONT= ("Verdana", 12)

#The Frame Title
window = Tk()
window.title("Edit Questionnaires")
label = Label(window, text= 'Personality Questions',font= FONT)
label.pack()

#this is the main body like a blank card (main command)
class MainFrame(Frame):
           def __init__ (self,master, in_text):
                      self.label_text = in_text
                      Frame.__init__(self,master)
                      label1 = Label(self, text = in_text)
                      label1.grid(row =0 ,column=0) 
                      e1 = Entry(self)
                      e2 = Entry(self)
                      e3 = Entry(self)
                      e4 = Entry(self)


           def Question1(self):
                      #Whats is inside the 1st question
                      Label(self, text="Forceful").grid(column = 0, row=2)
                      e1 = Entry(self)
                      e1.grid(row=2, column=1)
                      Label(self, text="lively").grid(column=2,row=2)
                      e2 = Entry(self)
                      e2.grid(row=2, column=3)
                      Label(self, text="Modest").grid(column=4,row=2)
                      e3 = Entry(self)
                      e3.grid(row=2, column=5)
                      Label(self, text="Tactful").grid(column=6,row=2)
                      e4 = Entry(self)
                      e4.grid(row=2, column=7)

           def edit (self):
                      def __init__ (self, Quesion1):
                                 self.show= edit
                                 print(e1.get(), e2.get(), e3.get(), e4.get()) 
#for the 1st question
m1 = MainFrame(window, "Question 1")
m1.pack( padx = 10, pady = 10)

#the reason for the m1 is because it looks of the main frame, if it is not there, python actually ask what is question1.
b1 = Button(window, text = "edit question 1", command= lambda : m1.Question1())
b1.pack(side = TOP)
# the reason for m2 is to call the entry and print it
m2= MainFrame(window, "Edit")
m2.pack(padx = 10, pady = 10)
b2 = Button(window, text = "save", command = lambda : e1.get ())
b2.pack(side = TOP)

window.mainloop()




Is This A Good Question/Topic? 0
  • +

Replies To: Problem with the get() function on GUI/Tkinter

#2 andrewsw   User is offline

  • So Smart! S-M-R-T!
  • member icon

Reputation: 6578
  • View blog
  • Posts: 26,715
  • Joined: 12-December 12

Re: Problem with the get() function on GUI/Tkinter

Posted 21 March 2015 - 01:46 PM

There are more issues with your code than a question over get(), as you can see in the screenshot with the red wavy lines.

Attached Image

Are you suggesting that your code runs? In which case, post your runnable version of this code.

In the screenshot I doubt that you want to define a new, nested, __init__ method. Some of the errors can be overcome (but not fixed) with the use of 'self', but you need to clarify (for yourself) what you need within the edit() method.
b2 = Button(window, text = "save", command = lambda : e1.get ())

You cannot refer to e1 in this line. This code is outside of the class-definition so e1 has no meaning here.

This post has been edited by andrewsw: 21 March 2015 - 01:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 Moon_Serenity   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-March 15

Re: Problem with the get() function on GUI/Tkinter

Posted 21 March 2015 - 02:12 PM

Well it works in terms that I get the frame with the Buttons; and when I click them (edit question 1) , it pop up the question and reset or empty the entry but when I click save, it gives me nothing.

The reason for "e1.get()" is because I wanted to test and see if I can get the entry in e1 but like you (andrewsw) said, it is nothing hence the problem.

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1