Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,050 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,562 people online right now. Registration is fast and FREE... Join Now!




entry.get() not cooperating

 
Reply to this topicStart new topic

entry.get() not cooperating

itpro4470
3 Aug, 2008 - 10:10 PM
Post #1

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 119



Thanked: 1 times
Dream Kudos: 25
My Contributions
I must be missing something but I just cant find it here's my code
CODE

#Longevity
#Demonstrates text entry widget and the grid layout manager

from Tkinter import *

class Application(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.grid()
        self.create_widgets()
    def create_widgets(self):
        #Instruction label
        self.inst_lbl = Label(self, text = "Enter password for the secret to longevity").grid(row = 0, column = 0, columnspan = 2, sticky = W)
        
        #Password label
        self.pwd_lbl = Label(self, text = "Password: ").grid(row = 1, column = 0, sticky = W)
        
        #Entry widget
        self.pw_ent = Entry(self).grid(row = 1, column = 1, sticky = W)
        
        #Submit button
        self.submit_bttn = Button(self, text = "Submit", command = self.reveal).grid(row = 2, column = 0, sticky = W)
        
        #Text box
        self.secret_txt = Text(self, width = 35, height = 5, wrap =WORD).grid(row = 3, column = 0, columnspan = 2, sticky = W)
    def reveal(self):
        contents = self.pw_ent.get() #This is where I get the error
        if contents == "secret":
            message = "Live to 99 then be really careful"
        else:
            message = "Incorrect password"
        self.secret_txt.delete(0.0,END)
        self.secret_txt.insert(0.0,message)
#main
root = Tk()
root.title("Longevity")
root.geometry("250x150")

app = Application(root)

root.mainloop()


this is the error I am getting
CODE

File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1406, in __call__
return self.func(*args)
File "/home/chaos/none", line 27, in reveal
contente = self.pw_ent.get()
AttributeError: 'NoneType' object has no attribute 'get'


WTF am I doing wrong?

This post has been edited by itpro4470: 3 Aug, 2008 - 10:12 PM
User is offlineProfile CardPM
+Quote Post

itpro4470
RE: Entry.get() Not Cooperating
4 Aug, 2008 - 07:53 AM
Post #2

D.I.C Head
Group Icon

Joined: 17 Jun, 2007
Posts: 119



Thanked: 1 times
Dream Kudos: 25
My Contributions
Ok I got somwhere but it's still not working. All of my Tkinter objects are initializing as NoneType is this normal?
User is offlineProfile CardPM
+Quote Post

linuxunil
RE: Entry.get() Not Cooperating
4 Aug, 2008 - 07:12 PM
Post #3

New D.I.C Head
Group Icon

Joined: 7 Mar, 2006
Posts: 46



Thanked: 2 times
Dream Kudos: 125
My Contributions
You can't initialize them and use .grid int he same line. Since all function in python return some thing even a None (or NoneType). So you should use something like this.
python

self.pwd_lbl = Label(master, text = "Password: ")
self.pwd_lbl.grid(row = 1, column = 0, sticky = W)

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:38PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month