2 Replies - 1155 Views - Last Post: 04 August 2008 - 08:12 PM Rate Topic: -----

#1 itpro4470  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 156
  • Joined: 17-June 07

entry.get() not cooperating

Posted 03 August 2008 - 11:10 PM

I must be missing something but I just cant find it here's my 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
 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: 03 August 2008 - 11:12 PM


Is This A Good Question/Topic? 0
  • +

Replies To: entry.get() not cooperating

#2 itpro4470  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 156
  • Joined: 17-June 07

Re: entry.get() not cooperating

Posted 04 August 2008 - 08:53 AM

Ok I got somwhere but it's still not working. All of my Tkinter objects are initializing as NoneType is this normal?
Was This Post Helpful? 0
  • +
  • -

#3 linuxunil  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 46
  • Joined: 07-March 06

Re: entry.get() not cooperating

Posted 04 August 2008 - 08:12 PM

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.
self.pwd_lbl = Label(master, text = "Password: ")
self.pwd_lbl.grid(row = 1, column = 0, sticky = W)


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1