0

Here is my code along with the error message.

from Tkinter import *

class Window01 (Frame):


def __init__(self, master):
Frame.__init__(self)
self.reveal()
self.create_widget()
self.grid()


def create_widget(self):

self.lbl = Label (self, text = "This is a Widget App.")
self.lbl.grid(row =1, column =0, columnspan =2, sticky = W)

self.entbx = Entry(self)
self.entbx.grid(row = 1, column = 1, sticky = W)

self.bttn = Button (self, text = "Widget Button", command = self.reveal)
self.bttn.grid(row = 2, column = 0, sticky = W)

self.txt = Text (self, width =35, height = 5, wrap = WORD)
self.txt.grid(row = 3, column = 0, columnspan =2, sticky = W)

def reveal (self):
contents = self.entbx.get()

if  contents =="magic":
message = "Access Granted"

else:
message = "Denied"
self.txt.delete(0.0, END)
elf.txt.insert(0.0, message)


root = Tk()
root.title ("Widget_Button")
root.geometry ("300x150")
app = Window01 (root)
root.mainloop()

File "C:\PyDev\Py_Widgets101\src\Py_Widget03.py", line 10, in init self.reveal() File "C:\PyDev\Py_Widgets101\src\Py_Widget03.py", line 30, in reveal contents = self.entbx.get() AttributeError: Window01 instance has no attribute 'entbx'

1
  • Fix the indentation in the question. Commented Jun 29, 2013 at 7:09

1 Answer 1

1

self.entbx is created by create_widget(). You are calling reveal() -- which requires self.entbx -- before you've called create_widget():

self.reveal()
self.create_widget()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.