python - 明确定义时未定义功能“注册”
问题描述
我遵循了有关使用 tkinter 创建登录应用程序的教程。一切都很顺利,我以为我理解了代码,直到我尝试运行它。出于某种原因,它告诉我“注册”没有明确定义。这是教程的链接。这就是我在 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()
如您所见,我刚刚编辑了笔记,因此我了解了更多我需要做的事情(即使它与教程基本相同)。我还尝试在 main_account_screen 函数下放置一些在教程中没有的代码,但它仍然无法工作。
解决方案
推荐阅读
- python - VSCode + Pytest:“错误:TypeError:无法读取未定义的属性'$'”
- android - react native报错包android.support.v7.app不存在
- javascript - 如何在电子中使用primus
- python - AttributeError:类型对象“DatasetV2”没有属性“from_tensor”
- javascript - 在javascript上将函数作为参数传递
- html - 如何在 Nginx 中使用动态生成的路由?
- c# - 错误“对象引用未设置为对象的实例。” 对于 CreateUserWithEmailAndPasswordAsync
- pytorch - 将 pytorch CNN 应用于视频?
- cowboy - 如何在牛仔服务器上禁用 HTTP 方法
- javascript - 如何获取事件的 textContent 长度