简体   繁体   English

登录屏幕哪里出了问题(Def Login)

[英]Where am i going wrong with the login screen (Def Login)

I'm working on some school work and i'm developing an app for car rentals, im working on the basics and learning as i go along.我正在做一些学校工作,我正在开发一个汽车租赁应用程序,我正在研究基础知识并学习 go。 The rest of the app is working so far but im looking into why my user login screen isn't functioning.该应用程序的 rest 到目前为止工作正常,但我正在调查为什么我的用户登录屏幕无法正常工作。

I've tried implementing some of the similar code within my register screen (which works flawlessly) but the code launches, but when i press login i'm not getting any windows showing, it may be a simple mistake, but it's likely due to my lack of experience haha, i've also tried working with the global variables, but that is where i feel i lack my most knowledge in understand global variables and where to use them appropriately.我已经尝试在我的注册屏幕中实现一些类似的代码(它完美地工作)但是代码启动了,但是当我按下登录时我没有得到任何 windows 显示,这可能是一个简单的错误,但这可能是由于我缺乏经验哈哈,我也尝试过使用全局变量,但这就是我觉得我在理解全局变量以及在哪里适当使用它们方面缺乏我最了解的地方。

import tkinter as tk

def register():
    top = tk.Toplevel(root)  # create a GUI window
    top.title("Register")
    top.geometry("400x350")
    username = tk.StringVar(top)
    password = tk.StringVar(top)
    email = tk.StringVar(top)
    tk.Label(top, text="Please enter your details below", bg="red").pack()
    tk.Label(top, text="Email * ").pack()
    tk.Entry(top, textvariable=email).pack(padx=10, pady=10)
    tk.Label(top, text="Username * ").pack()
    tk.Entry(top, textvariable=username).pack(padx=10, pady=10)
    tk.Label(top, text="Password * ").pack()
    tk.Entry(top, textvariable=password, show='*').pack(padx=10, pady=10)
    tk.Button(top, text="Register", width=10, height=2, bg="red").pack()

def login():
    login_screen = tk.Toplevel(root) 
    login_screen.title("Login")  
    login_screen.geometry("300x250") 
    username_verify = tk.StringVar(login_screen) 
    password_verify = tk.StringVar(login_screen)
    tk.Label(login_screen, text="Please enter details below to login").pack()
    tk.Label(login_screen, text="").pack()

    global username_login_entry
    global password_login_entry

    tk.Label(login_screen, text="Username * ").pack()
    username_login_entry = tk.Entry(login_screen, textvariable=username_verify)
    username_login_entry.pack()
    tk.Label(login_screen, text="").pack()
    tk.Label(login_screen, text="Password * ").pack()
    password_login_entry = tk.Entry(login_screen, textvariable=password_verify, show='*')
    password_login_entry.pack()
    tk.Label(login_screen, text="").pack()
    tk.Button(login_screen, text="Login", width=10, height=1, command=login_verify).pack()

root = tk.Tk()
root.geometry("700x450")
root.title("Account Login")
root.wm_iconbitmap('py.ico')
tk.Label(root, text="Login or Register", bg="red", width="300", height="2", font=("Arial Black", 13,)).pack()
tk.Button(root, text="Login", height="4", width="30", font=("Arial Black", 13,)).pack(padx=15, pady=15)
tk.Button(root, text="Register", height="4", width="30", font=("Arial Black", 13,), command=register).pack()

root.mainloop()

In this code im particularly looking at the Def Login part of the code but i provided all of my lines so far as context to help you understand if there are any issues that are linking to the other functions.在这段代码中,我特别查看了代码的 Def Login 部分,但我提供了我所有的行作为上下文,以帮助您了解是否存在链接到其他函数的任何问题。 The expected output would be where the login window opens when clicked.预期的 output 将是登录 window 在单击时打开的位置。

You've done the definition correctly, however you've never used that function anywhere.您已经正确完成了定义,但是您从未在任何地方使用过 function。 Notice how the register function has been called through this line注意register function 是如何通过这一行调用的

tk.Button(root, text="Register", height="4", width="30", font=("Arial Black", 13,), command=register).pack()

command=register is what calls the function upon pressing the button. command=register是按下按钮时调用的 function。 However, you don't have a command associated with your login button.但是,您没有与登录按钮关联的命令。

tk.Button(root, text="Login", height="4", width="30", font=("Arial Black", 13,)).pack(padx=15, pady=15)

Notice the lack of a command attribute.请注意缺少command属性。 I'm sure you know what to do now:)我相信你现在知道该怎么做了:)

Remember one thing in your login definition.在您的login定义中记住一件事。 In the very last line, you're calling command=login_verify .在最后一行,您正在调用command=login_verify I'm assuming you simply have that as a placeholder for a function you'll be working on later but that will throw an exception, just letting you know.我假设您只是将它作为 function 的占位符,稍后您将进行处理,但这会引发异常,只是让您知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM