Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Python Tkinker entry problem

  • 26-09-2009 07:00PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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