Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法重定向到注册页_Python_Tkinter - Fatal编程技术网

Python 无法重定向到注册页

Python 无法重定向到注册页,python,tkinter,Python,Tkinter,当我运行我的登录页面并单击“注册”按钮时,它不会重定向到“注册”页面,而只是在登录页面上进行维护 import register import pymysql class Login: def __init__(self,root): self.root=root self.root.title("Scheduling Management System") self.root.geometry("1

当我运行我的登录页面并单击“注册”按钮时,它不会重定向到“注册”页面,而只是在登录页面上进行维护

import register  
import pymysql

class Login:


    def __init__(self,root):
        self.root=root
        self.root.title("Scheduling Management System")
        self.root.geometry("1350x768+0+0")
        self.root.resizable(False,False)

        self.txt_user = StringVar()
        self.txt_pass = StringVar()
        self.bg = ImageTk.PhotoImage(file = "Images/bgimage.jpg")
        bg = Label(self.root,image=self.bg).place(x = 0, y= 0, relwidth = 1, relheight = 1)
        framelogin = Frame(self.root,bg="white")
        framelogin.place(x=450,y=100,height=500,width=700)

        title=Label(framelogin,text="Login Here",font=("Arial",30,"bold"),fg="orange",bg="white").place(x=90,y=30)
        nexttitle=Label(framelogin,text="Scheduling Staff System",font=("Times New Roman",18,"bold"),fg="orange",bg="white").place(x=90,y=100)

        userlabel=Label(framelogin,text="Username",font=("Arial",15,"bold"),fg="gray",bg="white").place(x=90,y=140)
        self.txt_user=Entry(framelogin,textvariable = self.txt_user,font=("times new roman",15),bg="lightgray")
        self.txt_user.place(x=90,y=170,width=350,height=35)

        passlabel=Label(framelogin,text="Password",font=("Arial",15,"bold"),fg="gray",bg="white").place(x=90,y=210)
        self.txt_pass=Entry(framelogin,textvariable = self.txt_pass,font=("times new roman",15),show="*",bg="lightgray")
        self.txt_pass.place(x=90,y=240,width=350,height=35)

        forget=Button(framelogin,text="Forgot Password",bg="white",fg="orange",font=("trebuchet ms",12)).place(x=90,y=305)
        reglabel=Label(framelogin,text="Don't Have an Account?",font=("trebuchet ms",12,"bold"),fg="orange",bg="white").place(x=320,y=310)
        registerbutton=Button(framelogin,text="Sign Up",command=register,bg="white",fg="orange",font=("trebuchet ms",12)).place(x=510,y=305)

        loginbutton=Button(framelogin,text="Login",command=self.login,fg="white",bg="orange",font=("sans serif ms",20)).place(x=90,y=350,width="100",height="40")

    def login(self):
        if self.txt_user.get() == "" or self.txt_pass.get() == "":
            messagebox.showerror("Error", "Please fill up all fields!")


root = Tk()
obj = Login(root)
root.mainloop()
这是我的登记页

from tkinter import *
from tkinter import ttk, messagebox

import PIL
import pymysql
from PIL import ImageTk
from PIL import Image

class Register:
    def __init__(self, root):
        self.root = root
        self.root.title("Registration Page")
        self.root.geometry("1350x768+0+0")
        self.root.config(bg="light blue")

        self.bg = ImageTk.PhotoImage(file="Images/bgimage.jpg")
        bg = Label(self.root,image=self.bg).place(x = 0, y= 0, relwidth = 1, relheight = 1)
        frame1=Frame(self.root,bg="white")
        frame1.place(x=450,y=100,width=700,height=600)

        title=Label(frame1,text="Please enter your information here",font=("trebuchet ms",20,),bg="white",fg="black").place(x=50, y=30)


        fname=Label(frame1,text="First Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50, y=100)
        self.text_fname=Entry(frame1,font=("arial",15,),bg="lightgray")
        self.text_fname.place(x=50, y=130, width=250)
        lname=Label(frame1,text="Last Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370, y=100)
        self.text_lname=Entry(frame1,font=("arial",15,),bg="lightgray")
        self.text_lname.place(x=370, y=130, width=250)
        contact=Label(frame1,text="Contact Number",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50, y=170)
        self.text_contact=Entry(frame1,font=("arial",15,),bg="lightgray")
        self.text_contact.place(x=50, y=200, width=250)
        email=Label(frame1,text="Email Address",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370, y=170)
        self.text_email=Entry(frame1,font=("arial",15,),bg="lightgray")
        self.text_email.place(x=370, y=200, width=250)
        question=Label(frame1,text="Security Question",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50, y=240)
        self.cmbquestion=ttk.Combobox(frame1,font=("times new roman",13),state='readonly',justify=CENTER)
        self.cmbquestion['values']=("Select","Your First Car","Your Mothers First Name", "Your Best Friend Name")
        self.cmbquestion.place(x=50, y=270, width=250)
        self.cmbquestion.current(0)
        answer=Label(frame1,text="Answer",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370, y=240)
        self.text_answer=Entry(frame1,font=("arial",15,),bg="lightgray")
        self.text_answer.place(x=370, y=270, width=250)
        pwd=Label(frame1,text="Password",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50, y=310)
        self.text_pwd=Entry(frame1,font=("arial",15,),show="*",bg="lightgray")
        self.text_pwd.place(x=50, y=340, width=250)
        cfmpwd=Label(frame1,text="Confirm Password",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370, y=310)
        self.text_cfmpwd=Entry(frame1,font=("arial",15,),show="*",bg="lightgray")
        self.text_cfmpwd.place(x=370, y=340, width=250)

        self.btn= ImageTk.PhotoImage(file="images/register.png")
        btn = Button(frame1,image=self.btn, bd=0, command = self.registerdata,cursor = "hand2").place(x=50, y = 420)



    def registerdata(self):
        if self.text_fname.get()=="" or self.text_lname.get()=="" or self.text_contact.get()=="" or self.text_email.get()=="" or self.cmbquestion.get()=="Select" or self.text_pwd.get()=="" or self.text_cfmpwd.get()=="":
            messagebox.showerror("Error","All fields are required!",parent=self.root)
        elif self.text_pwd.get()!=self.text_cfmpwd.get():
            messagebox.showerror("Error","Passwords must be the same!",parent=self.root)
        else:
            try:
                con=pymysql.connect(host="localhost",user="root",password="",database="employee")
                cur=con.cursor()
                cur.execute("select * from employeelist where email=%s", self.text_email.get())
                row=cur.fetchone()
                print(row)
                if row!=None:
                    messagebox.showerror("Error","User Already Exists. Please Register With a New Email",parent=self.root)
                else:
                    cur.execute("insert into employeelist (fname,lname,contact,email,question,answer,password) values(%s,%s,%s,%s,%s,%s,%s)",
                                (self.text_fname.get(),self.text_lname.get(),self.text_contact.get(),self.text_email.get(),self.cmbquestion.get(),self.text_answer.get(),self.text_pwd.get()))
                    con.commit() #do changes to database
                    con.close()
                    messagebox.showinfo("Success","Registration Successful",parent=self.root)
            except Exception as ex:
                messagebox.showerror("Error",f"Error due to: {str(ex)}",parent=self.root)


root = Tk()
obj = Register(root)
root.mainloop()

我已经将按钮的操作插入为
command=register
,但它仍然没有重定向到register页面。“我的命令”功能有错误吗?

最好将主块代码移到函数中的寄存器.py中:

类寄存器:
...
def RegisterForm():
win=顶级()
obj=寄存器(win)
然后,您可以在登录页面内使用此功能:

导入寄存器
...
类登录:
定义初始化(自):
...
按钮(framelogin,text=“Sign Up”,command=self.register,bg=“white”,fg=“orange”,font=(“投石机ms”,12))。放置(x=510,y=305)
...
def寄存器(自):
register.RegisterForm()

在这里,我在主窗口/框架上制作了一个注册框架,并将其提升到所有现有框架之上。然后,当按下提交按钮时,该框架将被销毁

class login:
    def __init__(self):
        button=tk.Button(command=self.register)
    def register(self):
        f1=tk.Frame(root)
        f1.tkraise()
        boo=tk.Button(text='submit',command=f1.destroy)

它抛出“模块不可调用”错误?因为
register
是一个模块,而不是一个命令。我应该执行类似
register.register
的操作吗?