-1

I am trying to make a Jenga Scorer and I am just making a players list. When making this, I stumbled upon that I can't get an attribute from an Entry.

The qadd is the function that does this. Code:

from tkinter import *

players = []

def questionw():
    def addplayer():
        player = qentry.get()
        players.append(player)

    question = Tk()

    question.geometry("200x150")
    qentry = Entry(question,).place(y=60, x=3, width=195, height=20)
    qlabel = Label(question, text="What is the name\nof the player?", justify=CENTER, font=("Amasis MT Pro",12)).pack()
    qdone = Button(question, text="Done").place(y=90, x=10, width=80)
    qadd = Button(question, text=f"Add ({len(players)})", command=addplayer).place(y=90, x=100, width=80)
    qdone = Button(question, text="Cancel").place(y=120, x=55, width=80)

    question.mainloop()

question()

When I type something in Add button, it returns this on the console:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\user\Desktop\jenga.py", line 5, in addplayer
    player=qentry.get()
AttributeError: 'NoneType' object has no attribute 'get'
MichaelCG8
  • 579
  • 2
  • 14

1 Answers1

1

The traceback is telling you that qentry is not currently an Entry, it is None. Also, you are assigning qentry the return value of the place() method, not the initializer of Entry.

Try this:

qentry = Entry(question,)
qentry.place(y=60, x=3, width=195, height=20)
MichaelCG8
  • 579
  • 2
  • 14