在Tkinter中创建复杂的登录和注册系统

时间:2017-09-28 12:41:31

标签: python file tkinter

我在python 3.3中创建一个程序,同时使用tkinter,它应该注册用户的个人信息,例如他们的电子邮件名和第二名。到目前为止,用户可以自己注册,他们的信息将保存在文件中。但是,有一个错误。如果用户已经创建了一个帐户,当他们输入登录详细信息并单击“提交”时,程序不会读取该文件并且不会进行任何描述。因此,我希望程序读取用户的详细信息是否存在于文件中。 这是我的代码:

def init_screen(self):

    self.MainScreen.title("Sonico Services")

    self.MainScreen.configure(background = "#ffff00")        

    self.pack(fill=BOTH, expand=1)

    RegisterButton = Button(self, text="Register", bg = "red", fg = "yellow",command=self.User_Register)

    RegisterButton.place(x=200,y=100)

    LoginButton=Button(self,text="Login",bg="red",fg="yellow",command=self.User_Login)

    LoginButton.place(x=270,y=100)

def User_Register(self):
    Firstname=Label(application,text="First Name: ",bg="yellow",fg="red").grid(row=30,column=7)
    Secondname=Label(application,text="Second Name: ",bg="yellow",fg="red").grid(row=30,column=10)
    Emailtag=Label(application,text="Email address: ",bg="yellow",fg="red").grid(row=15,column=7)
    Password=Label(application,text="Password : ",bg="yellow",fg="red").grid(row=35,column=7)
    SubmitButton=Button(self,text="Submit",bg="red",fg="yellow",command=self.File_Manipulation)
    SubmitButton.place(x=140,y=100)
    EntryBox1=Entry(application)
    EntryBox2=Entry(application)
    EntryBox3=Entry(application)
    EntryBox4=Entry(application)
    EntryBox1.grid(row=30,column=12)
    EntryBox2.grid(row=30,column=8)
    EntryBox3.grid(row=15,column=8)
    EntryBox4.grid(row=35,column=8)
    global EntryBox1
    global EntryBox2
    global EntryBox3
    global EntryBox4
def File_Manipulation(self):
    with open("Client Data.txt","w+")as client_file:
        EB=EntryBox1.get()
        EB2=EntryBox2.get()
        EB3=EntryBox3.get()
        EB4=EntryBox4.get()
        infocombo=EB +(",")+ EB2+(",")+EB3+(",")+EB4+("\n")
        client_file.write(infocombo)
def User_Login(self):
    Firstname=Label(application,text="First Name: ",bg="yellow",fg="red").grid(row=30,column=7)
    Password=Label(application,text="Password : ",bg="yellow",fg="red").grid(row=35,column=7)
    EntryBox1=Entry(application)
    EntryBox4=Entry(application)
    EntryBox1.grid(row=30,column=8)
    EntryBox4.grid(row=35,column=8)
    SubmitButton=Button(self,text="Submit",bg="red",fg="yellow",command=self.Data)
    SubmitButton.place(x=140,y=100)
    EB4=EntryBox4.get()
    EB1=EntryBox1.get()
    global EB1
    global EB4
def Data(self):
    data=open("Client Data.txt","w+")
    read=data.readlines()
    for line in read:
        if (EB4+EB1) in line:
            WelcomeLabel=Label(application,text="Welcome! you have successfully logged in",bg="yellow",fg="red").grid(row=30,column=10)
        else:
            ExitLabel=Label(application, text= "Your account does not exist, please register first",bg="yellow",fg="red").grid(row=30,column=10)        

1 个答案:

答案 0 :(得分:0)

您需要做的就是使用MockMvc将文件读入您​​的程序,然后查看下面的列表:

.readlines()