I followed a tutorial about creating a log in application using tkinter. Everything was going good and I thought I understood the code until I tried running it. For some reason it tells me that "register" is not defined when it clearly is. Here's the link to the tutorial. And here is what I had in visual studio 2019.
import tkinter as tk
def main_account_screen():
main_screen = tk.Tk() #this creates the GUI window
main_screen.geometry('800x600') #this sets the window size
main_screen.title('Account LogIn') #this sets the title of the window
#this creates a Form label
tk.Label(text = 'Choose: LogIn or Register').pack()
tk.Label(text = '').pack()
#this creates the LogIn Button
tk.Button(text = 'LogIn').pack()
tk.Label(text = '').pack()
#this creates a Register Button
#add command = register in button widget
tk.Button(text = 'Register', command = register).pack()
main_screen.mainloop() #this starts the GUI
main_account_screen() #this calls the main_account_screen() function
#now you need to create a registration window
def register():
# The Toplevel widget works pretty much like a Frame,
# but it is displayed in a separate, top-level window.
#Such windows usually have title bars, borders, and other “window decorations”.
# And in the argument we have to pass the global screen variable
register_screen = tk.Toplevel(main_screen)
register_screen.title('Register')
register_screen.geometry('600x400')
#now you need to set the text variables where you'll store the data
username = StringVar()
password = StringVar()
#now you need a label that gives the user instructions
tk.Label(register_screen, text = 'Enter your detail below').pack()
tk.Label(register_screen, text = '').pack()
#now you need to set an username label
username_label = tk.Label(register_screen, text = 'Username * ')
username_label.pack()
#now it's time for the username entry
username_entry = tk.Entry(register_screen, textvariable = username)
username_entry.pack()
#now you need to set a password label
password_label = tk.Label(register_screen, text = 'Password * ')
password_label.pack
#now it's time for the password entry
password_entry = tk.Entry(register_screen, textvariable = password)
password_entry.pack()
tk.Label(register_screen, text = '').pack()
#now it's finally time for the register button
tk.Button(register_screen, text = 'Register').pack()
As you can see I just edited the notes so I understand more of what I need to do (even though it's basically the same as the tutorial). I also tried putting some code under the main_account_screen function that in the tutorial wasn't and it still won't work.