2017-10-04 1 views
-1

tkinter 암호 입력에 대한 유효성 검사를 위해 막대한 노력을했습니다. 내가 원하는 것은 사용자가 '로그인'버튼을 누르면 프로그램이 비밀번호를 확인하는 것입니다. 암호를 읽을 수있는 텍스트 파일에 저장하겠습니다. 파일 읽기를 구현하는 방법을 알고 있지만 암호가 받아 들여지면 프레임을 전환하는 방법을 알 수 없습니다.Tkinter 암호 검사기 (프레임 전환)

import tkinter as tk 
import tkinter.messagebox as tm 
from tkinter import * 

LARGE_FONT = ("Verdana", 12) 

Background = ('#e6eeff') 

class roomBooker(tk.Tk): 
    def __init__(self, *args, **kwargs): 

     tk.Tk.__init__(self, *args, **kwargs) 
     container = tk.Frame(self) 

     container.pack(side="top", fill="both", expand = True) 
     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 

     self.frames = {} 
     for F in (loginPage, signupPage, mainMenu): 
      frame = F(container, self) 
      self.frames[F] = frame 
      frame.grid(row=0, column=0, sticky="nsew") 
     self.show_frame(loginPage) 

    def show_frame(self, cont): 
     frame = self.frames[cont] 
     frame.configure(background='#e6eeff') 
     frame.tkraise() 


def show_frame(self, cont): 
    frame = self.frames[cont] 
    frame.configure(background='#e6eeff') 
    frame.tkraise() 

class loginPage(tk.Frame): 
    def __init__(self, master, controller): 
     tk.Frame.__init__(self,master) 

     self.title_1 = tk.Label(self, text="Room Booker 1.1",bg=Background ,font=("Verdana", 18)) 
     self.title_1.place(x=500, y=150) 

     self.label_1 = tk.Label(self, text="Username:",bg=Background ,font=("Verdana", 12)) 
     self.label_1.place(x=500, y=200) 

     self.entry_1 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_1.place(x=600, y=203) 

     self.label_2 = tk.Label(self, text="Password:",bg=Background ,font=("Verdana", 12)) 
     self.label_2.place(x=500, y=250) 

     self.entry_2 = tk.Entry(self, show="*", bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_2.place(x=600, y=253) 

     self.logbtn = tk.Button(self, text="Login", command=self._password_check, font=("Verdana", 10), width=14, relief=GROOVE) 
     self.logbtn.place(x=600, y=293) 

     self.button = tk.Button(self, text="Signup Now",command=lambda: controller.show_frame(signupPage), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.button.place(x=600, y=333) 


    def _password_check(self): 
     print("Clicked") 

     username = self.entry_1.get() 
     password = self.entry_2.get() 
     print(username, password) 

     if username == "test" and password == "test": 
      tm.showinfo("Login info", "Welcome Test") 
      show_frame(mainMenu) 
     else: 
      tm.showerror("Login error", "Incorrect username or password") 


class signupPage(tk.Frame): 

    def __init__(self, master, controller): 
     tk.Frame.__init__(self, master) 

##  button1 = tk.Button(self, text="Back to Home", 
##       command=lambda: controller.show_frame(loginPage)) 
##  button1.pack() 

     self.title_1 = tk.Label(self, text="Signup",bg=Background ,font=("Verdana", 18)) 
     self.title_1.place(x=500, y=150) 

     self.title_1 = tk.Label(self, text="Please enter a new username and password",bg=Background ,font=("Verdana", 8)) 
     self.title_1.place(x=500, y=185) 

     self.label_1 = tk.Label(self, text="Email:",bg=Background ,font=("Verdana", 12)) 
     self.label_1.place(x=500, y=200) 

     self.entry_1 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_1.place(x=600, y=203) 

     self.label_2 = tk.Label(self, text="Username:",bg=Background ,font=("Verdana", 12)) 
     self.label_2.place(x=500, y=250) 

     self.entry_2 = tk.Entry(self, show="*", bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_2.place(x=600, y=253) 

     self.label_3 = tk.Label(self, text="Password:",bg=Background ,font=("Verdana", 12)) 
     self.label_3.place(x=500, y=300) 

     self.entry_3 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_3.place(x=600, y=303) 

     self.logbtn = tk.Button(self, text="Signup",command=lambda: controller.show_frame(mainMenu), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.logbtn.place(x=600, y=343) 

     self.button = tk.Button(self, text="Return to Login",command=lambda: controller.show_frame(loginPage), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.button.place(x=600, y=383)  


class mainMenu(tk.Frame): 
    def __init__(self, master, controller): 
     tk.Frame.__init__(self, master) 

     label = tk.Label(self, text="Main Menu",bg=Background ,font=("Verdana", 18)) 
     label.pack(pady=10,padx=10) 

     button1 = tk.Button(self, text="Back to Home", 
          command=lambda: controller.show_frame(loginPage)) 
     button1.pack() 


app = roomBooker() 
app.geometry('1280x720') 
app.configure(background='#e6eeff') 
app.title('Room Booker') 
app.wm_iconbitmap("applicationlogo.ico") 
app.mainloop() 

답변

1

_password_check에 따른 귀하의 show_frame 호출이 올바르지 사전에 감사합니다. 이것을 시도하십시오 :

import tkinter as tk 
import tkinter.messagebox as tm 
from tkinter import * 

LARGE_FONT = ("Verdana", 12) 

Background = ('#e6eeff') 

class roomBooker(tk.Tk): 
    def __init__(self, *args, **kwargs): 

     tk.Tk.__init__(self, *args, **kwargs) 
     container = tk.Frame(self) 

     container.pack(side="top", fill="both", expand = True) 
     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 

     self.frames = {} 
     for F in (loginPage, signupPage, mainMenu): 
      frame = F(container, self) 
      self.frames[F] = frame 
      frame.grid(row=0, column=0, sticky="nsew") 
     self.show_frame(loginPage) 

    def show_frame(self, cont): 
     frame = self.frames[cont] 
     frame.configure(background='#e6eeff') 
     frame.tkraise() 

class loginPage(tk.Frame): 
    def __init__(self, master, controller): 
     tk.Frame.__init__(self,master) 

     self.title_1 = tk.Label(self, text="Room Booker 1.1",bg=Background ,font=("Verdana", 18)) 
     self.title_1.place(x=500, y=150) 

     self.label_1 = tk.Label(self, text="Username:",bg=Background ,font=("Verdana", 12)) 
     self.label_1.place(x=500, y=200) 

     self.entry_1 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_1.place(x=600, y=203) 

     self.label_2 = tk.Label(self, text="Password:",bg=Background ,font=("Verdana", 12)) 
     self.label_2.place(x=500, y=250) 

     self.entry_2 = tk.Entry(self, show="*", bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_2.place(x=600, y=253) 

     self.logbtn = tk.Button(self, text="Login", command=self._password_check, font=("Verdana", 10), width=14, relief=GROOVE) 
     self.logbtn.place(x=600, y=293) 

     self.button = tk.Button(self, text="Signup Now",command=lambda: controller.show_frame(signupPage), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.button.place(x=600, y=333) 


    def _password_check(self): 
     print("Clicked") 

     username = self.entry_1.get() 
     password = self.entry_2.get() 
     print(username, password) 

     if username == "test" and password == "test": 
      tm.showinfo("Login info", "Welcome Test") 
      app.show_frame(mainMenu) 
     else: 
      tm.showerror("Login error", "Incorrect username or password") 


class signupPage(tk.Frame): 

    def __init__(self, master, controller): 
     tk.Frame.__init__(self, master) 

##  button1 = tk.Button(self, text="Back to Home", 
##       command=lambda: controller.show_frame(loginPage)) 
##  button1.pack() 

     self.title_1 = tk.Label(self, text="Signup",bg=Background ,font=("Verdana", 18)) 
     self.title_1.place(x=500, y=150) 

     self.title_1 = tk.Label(self, text="Please enter a new username and password",bg=Background ,font=("Verdana", 8)) 
     self.title_1.place(x=500, y=185) 

     self.label_1 = tk.Label(self, text="Email:",bg=Background ,font=("Verdana", 12)) 
     self.label_1.place(x=500, y=200) 

     self.entry_1 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_1.place(x=600, y=203) 

     self.label_2 = tk.Label(self, text="Username:",bg=Background ,font=("Verdana", 12)) 
     self.label_2.place(x=500, y=250) 

     self.entry_2 = tk.Entry(self, show="*", bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_2.place(x=600, y=253) 

     self.label_3 = tk.Label(self, text="Password:",bg=Background ,font=("Verdana", 12)) 
     self.label_3.place(x=500, y=300) 

     self.entry_3 = tk.Entry(self, bg='#abb5c6',font=("Verdana", 10)) 
     self.entry_3.place(x=600, y=303) 

     self.logbtn = tk.Button(self, text="Signup",command=lambda: controller.show_frame(mainMenu), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.logbtn.place(x=600, y=343) 

     self.button = tk.Button(self, text="Return to Login",command=lambda: controller.show_frame(loginPage), font=("Verdana", 10), width=14, relief=GROOVE) 
     self.button.place(x=600, y=383)  


class mainMenu(tk.Frame): 
    def __init__(self, master, controller): 
     tk.Frame.__init__(self, master) 

     label = tk.Label(self, text="Main Menu",bg=Background ,font=("Verdana", 18)) 
     label.pack(pady=10,padx=10) 

     button1 = tk.Button(self, text="Back to Home", 
          command=lambda: controller.show_frame(loginPage)) 
     button1.pack() 


app = roomBooker() 
app.geometry('1280x720') 
app.configure(background='#e6eeff') 
app.title('Room Booker') 
app.mainloop() 

또한 중복 된 show_frame 기능은 제 생각에는 필요하지 않습니다.

+0

정말 고마워요! 나는 그것이 '앱'이라고 믿을 수 없다. 나에게 많은 문제를 일으켰다. – ChocolateSteak