yenxi
yenxi

Reputation: 13

Attempting to get data from Entry widget(tkinter)

 def AppendModule():
        Message = Label(GUIWindows.root, text="please type the ID of the module you want to append").grid(rows=6, column=0)
        ModuleInput = Entry(GUIWindows.root).grid(rows=6, column=0)
        ModuleInput.pack()
        AcceptButton = Button(GUIWindows.root, text='Enter ID', command=ModuleInput).grid(rows=8, column=0)
        e = ModuleInput.get
        print(e)

So this function is suppose to prompt the user to type the name of the module in the text box and then store what the user wrote as a variable. I'm getting the error (AttritubeError: 'NoneType' object has no attribute 'pack').
So I did a bit of research and I was told to use the .pack to store the data and then use the .get to retrieve it. Though that doesn't seem to work. Any Suggestions?

Upvotes: 1

Views: 43

Answers (1)

Зелди
Зелди

Reputation: 86

  1. You forgot to add parentheses. But even if you did this, you are still trying to get entry input right after creating it.
  2. As @Mike - SMT said, you are using both .grid() and .pack() methods, which is not allowed.
  3. You're trying to set ModuleInput ( which is Entry object ) as command attribute in AcceptButton. You should make a function or method that prints entry input and link it as command in AcceptButton.

So, try this:

def printTextInEntry():
    print(ModuleInput.get())

def AppendModule2():
    global ModuleInput
    Message = Label(GUIWindows.root, text="please type the ID of the module you want to append").grid(rows=6, column=0)
    ModuleInput = Entry(GUIWindows.root)
    ModuleInput.grid(rows=6, column=0)
    AcceptButton = Button(GUIWindows.root, text='Enter ID', command=printTextInEntry)
    AcceptButton.grid(rows=8, column=0)

Upvotes: 2

Related Questions