Okay so I'm trying to learn some GUI using tkinter following along this website's guide: https://realpython.com/python-gui-tkinter/#building-your-first-python-gui-application-with-tkinter Depending on how I run the code it works using IDLE verse shell.
What happens in Idle is it is calling name long before anything is ever actually typed in the entry. which is why the output is "" . Where in shell I can type something into the entry "john doe" and when I get to 'name' it has something it can output.
import tkinter as tk
window = tk.Tk()
label = tk.Label(text = "Name")
entry = tk.Entry()
label.pack()
entry.pack()
name = entry.get()
name
Typically you would create a button that initiates the .get
and start the mainloop for the window, like this:
import tkinter as tk
def print_entry(widget):
name = widget.get()
print(name)
window = tk.Tk()
label = tk.Label(text = "Name")
entry = tk.Entry()
button = tk.Button(text = "Get Entry",
command = lambda e = entry: print_entry(e))
label.pack()
entry.pack()
button.pack()
window.mainloop()