When I try to run this code, it is supposed to print the user input, but rather, it prints None every time , even though I am giving a value to the variable. What am I supposed to do? I don't get an error in the console either.
from tkinter import *
main_window= Tk()
#labels
Label(main_window, text="Name:").grid(row=0,column=0)
Label(main_window,text="Age:").grid(row=1,column=0)
#text input
name= Entry(main_window,width=30,borderwidth=1).grid(row =0,column=1)
#text input for Class
age= Entry(main_window,width=30,borderwidth=1,).grid(row =1,column=1)
#defines on click function
def on_click():
print(f"Name = {name}, Age = {age}") #prints none when clicked submit
#Button
Button(main_window,text="Submit",command =on_click).grid(row=2,column=1)
main_window.mainloop()
This is the Code
Output:
Name = None, Age = None