0

I want to get the text from 3 different entry boxes to 3 variables with the click of 1 button, but it gives me an error if I try to get more than 1.

from tkinter import StringVar
from tkinter import *


root = Tk()

a = Entry(root)
b = Entry(root)
c = Entry(root)

def callback():
    a_return = [a.get(),b.get(),c.get()]


b = Button(root, text="get", width=10, command=callback).pack()

mainloop()

    a_return = [a.get(),b.get(),c.get()]
AttributeError: 'NoneType' object has no attribute 'get'
Levi Jay
  • 3
  • 3
  • 3
    I don't think it's a good idea to have an Entry named `b` and also a Button named `b`. Try choosing different names for them. Also, [don't pack() on the same line that you assign the widget to a name](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-get) – Kevin Apr 15 '19 at 18:05

1 Answers1

3

You are trying to use b for more than one thing. First you set it to an entry, and then you set it to None when you create the button (because Button(...).pack() returns None).

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685