wardz
wardz

Reputation: 379

What causes this attribute error in python?

I can succesfully open the program but whenever I give the password entry an input it gives me this traceback/error.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__
    return self.func(*args)
  File "C:/Users/Frederik/Desktop/password.py", line 30, in reveal
    content = self.password.get()
AttributeError: Label instance has no attribute 'get'

I'm pretty new at python so I don't really know what causes this error. My code looks like this:

from Tkinter import *

class Application(Frame):
  """ GUI App """

  def __init__(self, master):
    """ Init the frame """
    Frame.__init__(self,master)
    self.grid()
    self.create_widgets()

  def create_widgets(self):
    """ Button, text and entry """
    self.instruction = Label(self, text = "Enter the password")
    self.instruction.grid(row = 0, column =0, columnspan = 2, sticky = W)
    self.password = Label(self, text = "Password: ")
    self.password.grid(row = 1, column = 0, columnspan = 2, sticky = W)

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

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

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

  def reveal(self):
    """ Display """
    content = self.password.get()

    if content == "fek_u_D8lan!":
      message = "Gratz, you feked D8lan!"

    else:
      message = "U failed to fek D8lan!"
    self.text.delete(0.0, END)
    self.text.insert(0.0, message)

root = Tk()
root.title("Fek Dolan")
root.geometry("250x150")
app = Application(root)

root.mainloop()

Upvotes: 1

Views: 174

Answers (1)

Avión
Avión

Reputation: 8376

You should get the enterpassword (the Entry), not the password (the Label). This should work:

content = self.enterpassword.get()

Upvotes: 3

Related Questions