首页 > 解决方案 > Python 登录窗口

问题描述

我正在尝试以代码输入我的登录系统,一切正常。但是当我打开文件并且我的登录窗口出现时,我按X登录窗口关闭,您可以继续使用该程序。

我的问题是:当有人没有登录整个程序应该关闭而不仅仅是登录窗口时,我该怎么做?

谢谢你的帮助!

我的代码:

import secrets
from tkinter import *
from tkinter import messagebox

def Ok():
    uname = e1.get()
    password = e2.get()
 
    if(uname == "" and password == "") :
        messagebox.showinfo("", "Blank Not allowed")
 
 
    elif(uname == "Admin" and password == "123"):
 
        messagebox.showinfo("","Login Success")
        root.destroy()
 
    else :
        messagebox.showinfo("","Incorrent Username and Password")
 
 
root = Tk()
root.title("Login")
root.geometry("300x200")
global e1
global e2
 
Label(root, text="UserName").place(x=10, y=10)
Label(root, text="Password").place(x=10, y=40)
 
e1 = Entry(root)
e1.place(x=140, y=10)
 
e2 = Entry(root)
e2.place(x=140, y=40)
e2.config(show="*")
 
 
Button(root, text="Login", command=Ok ,height = 3, width = 13).place(x=10, y=100)
 
root.mainloop()


pw = ""
zeichen = "QWERTZUIOPASDFGHJKLYXCVBNMqwertzuiopasdfghjklyxcvbnm123456789"
laenge = int(input("Bitte gib deine Passwortlänge ein: "))

for _ in range(laenge):
    pw = pw+secrets.choice(zeichen)

print(pw)

标签: pythontkinter

解决方案


推荐阅读