Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Python Tkinker entry problem

Options
  • 26-09-2009 7:00pm
    #1
    Registered Users Posts: 760 ✭✭✭


    I've been playing around with python and tkinter, i'm trying to craeat a simple caulator , i got the GUI sorted ,I'm trying to get functionality working so I'm a test programme

    I'm having problems get the input from the entry widget. To test this I have a function called get_input that is called when the button is pressed . Then it pass the input to a variable called a and printed to screen.

    I keep getting and error
    a=e1.get("1",END)
    AttributeError: 'NoneType' object has no attribute 'get'
    

    I googled and it said the variable wasn't declared so i set a="", but still not get the input.

    Here the code
    from Tkinter import *
    
    root = Tk()
    
    
    master = Frame(root)
    master.pack()
    
    # create entry widegt 
    e1=Entry(master).grid(row=0)
    
    
    # get the input from e1
    def get_input():
    	a=""
    	a=e1.get("1",END)
    	print a
    
    
      
    
    # create buttun and add call back
    button1 = Button(master, text="Pres Me",command=get_input)
    button1.grid(row=1, column=1)
    
    
    
    root.mainloop()
    

    can some explain what I doing wrong,I'm new to python .


Comments

  • Registered Users Posts: 760 ✭✭✭mach1982


    This isn't a homework problem i 'm just messing python, come on 21 people viewed, I've keep googleing but just can figure out the answer.Every time I've t I think I've solved up I come with that error. If some could explain what the error means then I might how to fix it , i've googled that too.


  • Registered Users Posts: 37 majestic0110


    I am no Python Guru myself but I am under the impression that the error is related to you trying to use a variable that has not been defined. I would print out the value of :
    e1=Entry(master).grid(row=0)
    

    as my next step in troubleshooting this. I hope this helps at all, but like I said, I am no Python guru!


  • Registered Users Posts: 37 majestic0110


    After some research, I might suggest you try to initialize e1 before you assign it the .grid function. I believe the .grid function returns a "NoneType", which would result in your error. Initialize e1 to the entry widget first, then assign it the return value of .grid. Something like this might work:
    e1=Entry(master)
    e1=grid(row=0)
    

    I hope this helps.


Advertisement