如何进入tktinker中的另一个窗口并销毁先前的窗口

时间:2020-07-23 16:42:05

标签: python tkinter

code

'''here is code for login''' 
    
    from tkinter import*
        from PIL import ImageTk
        
        from home import product
        from tkinter import messagebox
        import mysql.connector
        try:
            mydb1=mysql.connector.connect(
                        host='localhost',
                        user='root',
                        passwd='',
                        database='gg'
            )
            mycursor=mydb1.cursor()
        
        
        except mysql.connector.Error as error:
            messagebox.showinfo("Information", "No Server Connection")
            exit(0)
        class Please_Login:
        
            def __init__ (self,root):
                self.root=root
                self.root.title("Please Login")
                self.root.geometry("640x426+100+50")
                self.root.resizable(False, False)
                # self.bg=ImageTk.PhotoImage(file='Desktop/sanju.jpg')
                # self.bg_image=Label(self.root,image=self.bg).place(x=0,y=0,relwidth=1,relheight=1)
                global usename1
                global rollno1
                #frame login
                Frame_login = Frame(self.root, bg="white")
                Frame_login.place(x=305,y=70, height=340, width=320)
        
                #label for interface heading
                title = Label(Frame_login, text="LOGIN SYSTEM !!", font=("bahnschrift", 15, "bold"),
                              fg="black", bg="white").place(x=10, y=20)
                sam = Label(Frame_login, text="please login in here", font=("arial", 12, "bold"),
                            fg="black", bg="white").place(x=10, y=50)
                self.namevar=StringVar()
                self.pwvar=StringVar()
                #label and entry for username
                self.lbluser = Label(Frame_login, font=('Bahnschrift', 12, "bold"), text="USER NAME:"
                                     , fg="black", bg="white").place(x=10, y=90)
                self.txt_username = Entry(Frame_login, font=("Goudy old style", 15), bg="lavender",textvariable=self.namevar)
                self.txt_username.place(x=130, y=90, width=170, height=25)
        
                #label and entry for password
                self.lbluser = Label(Frame_login, font=('Bahnschrift', 12, "bold"), text="PASSWORD:"
                                     , fg="black", bg="white").place(x=10, y=130)
                self.txt_userpw = Entry(Frame_login, font=("Goudy old style", 15), bg="LAVENDER",textvariable=self.pwvar,show="*")
                self.txt_userpw.place(x=130, y=130, width=170, height=25)
        
                #login button
                self.login = Button(self.root, text="LOGIN", bg="white", fg="black",command=self.loginAdd  ,font=("Bahnschrift", 15, "bold"))
                self.login.place(x=330, y=250, width=250,height=30)
        
                #sign up button
                signup=Button(self.root,text="SIGN UP",bg="white",fg="black",
                             font=("Bahnschrift",15,"bold")).place(x=330, y=290, width=250, height=30)
        
                #reset button
                reset= Button(self.root, text="RESET", bg="white", fg="black",
                                font=("Bahnschrift", 15, "bold")).place(x=330, y=330, width=250, height=30)
        
                # forget password button
                forget = Button(Frame_login, text="Forget Password?", bg="white", fg="black", bd=0,
                                font=("Bahnschrift", 10, "bold")).place(x=10, y=310)
            def loginAdd(self):
                username1 = self.txt_username.get()
                rollno1 = self.txt_userpw.get()
                sql="SELECT * FROM login where username=%s"
                value=(username1,)
        
                mycursor.execute(sql, value)
                myresult = mycursor.fetchall()
                for i in myresult:
                    id = i[0]
                    pw = i[1]
        
                if (username1 == "" or rollno1 == ""):
                    messagebox.showinfo("Information", "Fill all the fields")
        
                elif (username1==id and rollno1==pw):
                    self.reg = Toplevel(self.root)
                    self.root.destroy()
                    product(self.reg)
        
        
                else:
                    messagebox.showinfo("Information","enter correct password and username")
        
        
        
        
        
        root=Tk()
        Please_Login(root)
        root.mainloop()
'''here is the code for home buttn'''
from tkinter import*
from PIL import ImageTk
import company
import manifest
class product:

        def __init__(self, root):
            self.root = root
            self.root.title("WAREHOUSE MANAGEMENT SYSTEM")
            self.root.geometry("1024x768+0+0")
            self.root.resizable(False, False)
            # self.bg = ImageTk.PhotoImage(file='Desktop/hello.jpg')
            # self.bg_image = Label(self.root, image=self.bg).place(x=0, y=0, relwidth=1, relheight=1)
            self.b1=Button (self.root,text="COMPANY",command=self.addcompany,font=('bahnschrift',20,'bold'))
            self.b2 = Button(self.root,text="MAINFEST",command=self.addcompany,font=('bahnschrift',20,'bold'))
            self.b3 = Button(self.root,text="WAREHOUSE",font=('bahnschrift',20,'bold'))
            self.b4 = Button(self.root,text="UPDATE",font=('bahnschrift',20,'bold'))
            self.b5 = Button(self.root,text="SHIPMENT",font=('bahnschrift',20,'bold'))
            self.b6 = Button(self.root,text="QUIT",font=('bahnschrift',20,'bold'))
            self.b1.place(x=30, y=50)
            self.b2.place(x=30,y=150)
            self.b3.place(x=30, y=250)
            self.b4.place(x=30, y=350)
            self.b5.place(x=30, y=450)
            self.b6.place(x=30, y=550)

        def addcompany(self):
            self.reg = Toplevel(self.root)
            company.product(self.reg)

        def addmanifest(self):
            self.reg = Toplevel(self.root)
            manifest.product(self.reg)

1 个答案:

答案 0 :(得分:0)

据我所知,您想做的事情是这样的:

我不知道课程,因此您可以自己添加课程。

def loginaccepted():
    home = Toplevel()
    root.withdraw()

Toplevel()创建Tk()的子级,root.withdraw()销毁窗口。如果要返回窗口,可以使用root.deiconify()

再次,我听不懂课堂,希望这能回答您的问题!