登录正确后如何更改屏幕? [英] How do i get screen to change once login correct?

查看:26
本文介绍了登录正确后如何更改屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两份代码,一个登录系统和一个学校申请,我想让它一旦我输入了正确的用户名和密码,我的学校申请就可以出现.我如何将两段代码合并在一起?

i have two peices of code,one login system and an application for school i want to make it that once i have entered the correct useransme and password my school application can come up. How would i merge both peices of code togther?

from tkinter import*
import tkinter.messagebox as messagebox
root=Tk()
root.geometry("600x300")

root.configure(bg='#003e53')
title=Label(root,text="Login", fg="white", bg="#003e53" ,font=("bold",15))
title.place(x=200, y=30)
uname=Label(root,text="User Name",fg="white",bg="#003e53",font=("bold",15))
uname.place(x=100,y=80)
password=Label(root,text="Password",fg="white",bg="#003e53",font=("bold",15))
password.place(x=100,y=110)
t_uname=Entry()
t_uname.place(x=200,y=80)
t_pwd=Entry()
t_pwd.place(x=200,y=110)

def validate_creds():
    uname=t_uname.get()
    password=t_pwd.get()
    if uname=="Supermarket" and password=="Password1":
        messagebox.showinfo(uname,"logged successfully")
    else:
        messagebox.showinfo(uname,"wrong credentials Mate")

submit=Button(root,text="Submit", command=validate_creds)
submit.place(x=200,y=140)
root.mainloop()

推荐答案

如果你想从另一个文件调用学校应用程序,你可以做一个函数,在登录成功后关闭当前的 Tkinter 窗口并启动文件包含使用模块 os 的学校应用程序.(另外,import * 不是一个好习惯)

If you wanted to call the school application program from another file, you would make a function which on logging in successfully, closes the current Tkinter window and launches the file containing the school application using the module os. (Also, it is not good practise to import *)

import os

#opening a file through the system
os.system("fily.py" "argument1")

至于合并两段代码,做两个不同的类,就这么简单!

As for merging the two pieces of code, make two different classes, as simple as that!

from tkinter import *

class window1:
    def __init__(self):
        self.root=Tk()
        self.root.geometry("600x300")

    def window(self):

        button = Button(self.root, text="Press to close window", command=self.closewindow)
        button.pack()

        self.root.mainloop()

    def closewindow(self):
        self.root.destroy()

class window2:
    def __init__(self):
        self.root=Tk()
        self.root.geometry("600x300")

    def window(self):
        title=Label(self.root,text="Hey this is a new window!", fg="white", bg="#003e53" ,font=("bold",15))
        title.place(x=200, y=30)

        self.root.mainloop()

    def closewindow(self):
        self.root.destroy()

tkinter1 = window1()
tkinter1.window()
tkinter2 = window2()
tkinter2.window()

另外,你可以在window1类中初始化window2类,并制作一个函数来替换self.closewindow来关闭窗口并打开新的

What's more, you can initialize the window2 class within the window1 class and make a function to replace self.closewindow to close the window and open the new one

这篇关于登录正确后如何更改屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆