내 프로그램이 탭과 같은 프레임을 변경하지 않는 이유는 무엇입니까?Python Tkinter 프레임
내 LoginPage는 사용자와 암호를 올바르게 확인하지만 유효성 검사 후 주 프로그램으로 어떻게 변경할 수 있는지 알지 못합니다.
import tkinter as tk
from tkinter import ttk
import dbm
class Program(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 = {}
Frames = (LoginPage, StartPage)
for F in Frames:
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column = 0, sticky="nsew")
self.ShowF(LoginPage)
def ShowF(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LoginPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
stats = tk.Label(self, text = 'Insira os dados para a validação')
stats.pack()
lab = tk.Label(self, text = ('Usuário'))
lab.pack()
self.ent = tk.Entry(self)
self.ent.pack()
lab2 = tk.Label(self, text = ('Senha'))
lab2.pack()
self.ent2 = tk.Entry(self, show='*')
self.ent2.pack()
but = tk.Button(self, text = 'Validar', command = self.Validacao)
but.pack()
self.lab3 = tk.Label(self, text = '')
self.lab3.pack()
def Validacao(self):
user = self.ent.get()
passw = self.ent2.get()
with dbm.open('files/contas','rb') as contas:
accv = [key1.decode() for key1 in contas.keys()]
passv = [contas[key].decode() for key in contas.keys()]
while True:
try:
k = accv.index(user)
k1 = passv.index(passw)
break
except:
self.lab3['text'] = ('Usuário e/ou senha inválidos!')
return
if k == k1:
self.lab3['text'] = ('Validação concluída!')
lambda :controller.ShowF(StartPage) #The problem is here(I think)
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Start Page")
label.pack(pady=10, padx=10)
button = tk.Button(self, text="Button1")
button.pack()
buttona = tk.Button(self, text="Button2")
buttona.pack()
app = Program()
app.mainloop()
프로그램이 어떻게 작동해야하는지 자세히 설명해 주시겠습니까? – Nae
로그인 화면 (로그인 페이지)에서 사용자와 암호를 확인한 다음 주요 기능 페이지 (anotherPage)에 주요 기능을 입력하십시오. –