
AttributeError: el objeto '_tkinter.tkapp' no tiene atributos 'frames''
Publicado por Andrés Felipe (3 intervenciones) el 04/11/2021 01:12:17
Tengo un error en la clase StartPage () quiero cambiar de página, si el nombre que ingreso en el Entry () es == "andres". En el método entrar () trato de poner un método de SampleApp () que es la primera clase que tengo, y la heredo en StartPage () y aun así no me funciona, he intentado muchas cosas. El método self.show_frame ("PageOne") lo tenia individual en un botón y me funcionaba correctamente, pero en el método entrar () no me quiere funcionar parece que no reconociera el diccionario que tengo en la primera clase StartPage ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import tkinter as tk
from tkinter import font as tkfont
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
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 (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame,SampleApp):
def __init__(self, parent, controller,*args,**kwargs):
tk.Frame.__init__(self, parent,*args,**kwargs)
self.controller = controller
self.config(bg="red")
self.nombre=tk.StringVar()
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
self.button1 = tk.Button(self, text="Go to Page One",
command=self.entrar)
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
self.texto = tk.Entry(self,textvariable=self.nombre)
self.button1.pack()
button2.pack()
self.texto.pack()
def entrar(self):
if self.nombre.get()=="andres":
self.show_frame("PageOne")
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.config(bg="blue")
label = tk.Label(self, text="This is page 1", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.config(bg="green")
label = tk.Label(self, text="This is page 2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
if __name__== "__main__":
app = SampleApp()
app.mainloop()
Valora esta pregunta


0