你好朋友,我有这个基本的登录窗口,一切都工作正常,但我想在我按下登录并且一切正常时它会关闭并将我发送到另一个窗口,即仪表板
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from PIL import Image,ImageTk
import sqlite3
def login():
#getting form data
uname=username.get()
pwd=password.get()
#applying empty validation
if uname=='' or pwd=='':
message.set("fill the empty field!!!")
else:
#open database
conn = sqlite3.connect('IMS.db')
#select query
cursor = conn.execute('SELECT * from employee where eid="%s" and pass="%s"'%(uname,pwd))
#fetch data
if cursor.fetchone():
message.set("Login success")
else:
message.set("Wrong ID or password!!!")
#defining loginform function
def Loginform():
global login_screen
login_screen = Tk()
#Setting title of screen
login_screen.title("TDC Login")
#setting height and width of screen
login_screen.geometry("350x250")
login_screen["bg"]="#1C2833"
#declaring variable
global message;
global username
global password
username = StringVar()
password = StringVar()
message=StringVar()
#Creating layout of login form
Label(login_screen,width="300", text="Login From", bg="#0E6655",fg="white",font=("Arial",12,"bold")).pack()
#Username Label
Label(login_screen, text="ID * ",bg="#1C2833",fg="white",font=("Arial",12,"bold")).place(x=20,y=40)
#Username textbox
Entry(login_screen, textvariable=username,bg="#1C2833",fg="white",font=("Arial",12,"bold")).place(x=120,y=42)
#Password Label
Label(login_screen, text="Password * ",bg="#1C2833",fg="white",font=("Arial",12,"bold")).place(x=20,y=80)
#Password textbox
Entry(login_screen, textvariable=password ,show="*",bg="#1C2833",fg="white",font=("Arial",12,"bold")).place(x=120,y=82)
#Label for displaying login status[success/failed]
Label(login_screen, text="",textvariable=message,bg="#1C2833",fg="white",font=("Arial",12,"bold")).place(x=95,y=120)
#Login button
Button(login_screen, text="Login", width=10, height=1, command=login, bg="#0E6655",fg="white",font=("Arial",12,"bold")).place(x=125,y=170)
login_screen.mainloop()
#calling function Loginform
Loginform()
找不到在我当前页面和设置上应用的方法
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from PIL import Image, ImageTk
import sqlite3
def login():
# getting form data
uname = username.get()
pwd = password.get()
# applying empty validation
if uname == '' or pwd == '':
message.set("Fill the empty field!!!")
else:
# open database
conn = sqlite3.connect('IMS.db')
# select query
cursor = conn.execute('SELECT * from employee where eid="%s" and pass="%s"' % (uname, pwd))
# fetch data
if cursor.fetchone():
message.set("Login success")
# Close the login screen
login_screen.destroy()
# Open the mainForm
mainForm()
else:
message.set("Wrong ID or password!!!")
# defining loginform function
def Loginform():
global login_screen
login_screen = Tk()
# Setting title of screen
login_screen.title("TDC Login")
# setting height and width of screen
login_screen.geometry("350x250")
login_screen["bg"] = "#1C2833"
# declaring variable
global message
global username
global password
username = StringVar()
password = StringVar()
message = StringVar()
# Creating layout of login form
Label(login_screen, width="300", text="Login From", bg="#0E6655", fg="white", font=("Arial", 12, "bold")).pack()
# Username Label
Label(login_screen, text="ID * ", bg="#1C2833", fg="white", font=("Arial", 12, "bold")).place(x=20, y=40)
# Username textbox
Entry(login_screen, textvariable=username, bg="#1C2833", fg="white", font=("Arial", 12, "bold")).place(x=120, y=42)
# Password Label
Label(login_screen, text="Password * ", bg="#1C2833", fg="white", font=("Arial", 12, "bold")).place(x=20, y=80)
# Password textbox
Entry(login_screen, textvariable=password, show="*", bg="#1C2833", fg="white", font=("Arial", 12, "bold")).place(x=120,
y=82)
# Label for displaying login status[success/failed]
Label(login_screen, text="", textvariable=message, bg="#1C2833", fg="white", font=("Arial", 12, "bold")).place(
x=95, y=120)
# Login button
Button(login_screen, text="Login", width=10, height=1, command=login, bg="#0E6655", fg="white",
font=("Arial", 12, "bold")).place(x=125, y=170)
login_screen.mainloop()
def mainForm():
# Create the form you want to open
main_form = Tk()
main_form.title("Main Form")
# Add your main form layout and components here
main_form.mainloop()
# calling function Loginform
Loginform()
还没有测试过,所以请提供反馈,但是当插入正确的凭据时,您应该能够销毁登录表单,之后只需像您已经做的那样调用新表单即可。