0

recently I began to work with tkinter. I try to create a Grade manager and when I try to save the input from an Entry box, but every way I try, the result is an error or 'None'

 def check_value(self,Input_Name):
        Name = Input_Name.get()
        print(Name)
    def add_Student(self, window):
        print("Yes")
        Input_Name = tk.Entry(window, bg='blue').pack()
    
        Button(window, text="Show", command=lambda: self.check_value(Input_Name)).pack()

For this piece of code the following error is :

Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\tkinter_init_.py", line 1883, in call return self.func(*args) File "C:/Users/User/PycharmProjects/pythonProject/main.py", line 28, in Button(window, text="Show", command=lambda: self.check_value(window.Input_Name)).pack() File "C:/Users/User/PycharmProjects/pythonProject/main.py", line 20, in check_value Name = Input_Name.get() AttributeError: 'NoneType' object has no attribute 'get'

MrSaiba
  • 21
  • 6

1 Answers1

1

You are trying to assign the Input_Name to the result that is returned by .pack() method of the widget, not to the widget itself. .pack() method returns nothing. Consequently, you are trying to .get() something from a Nonetype object instead of a tk.Entry.

You need to assign the tk.Entry to the Input_Name variable first, and then just call method pack on the variable. Here is an example of fixed code:

def check_value(self,Input_Name):
    Name = Input_Name.get()
    print(Name)
def add_Student(self, window):
    print("Yes")
    Input_Name = tk.Entry(window, bg='blue')
    Input_Name.pack()
    Button(window, text="Show", command=lambda: self.check_value(Input_Name)).pack()
Demian Wolf
  • 1,698
  • 2
  • 14
  • 34