I have this program. But when I want to add an image, I get error:
AttributeError: 'Page1' object has no attribute 'tk'.
from tkinter import *
from customtkinter import *
from PIL import Image
app = CTk()
app.configure(fg_color='#dda15e')
app.title('School Project')
app.resizable(width=False, height=False)
app.geometry('690x520')
def hide_all():
""" Hides all the pages """
page1.hide()
def show_page1():
page1.show()
class Page1:
def __init__(self):
super().__init__()
self.on_img = CTkImage(light_image=Image.open("main1.png"),size=(300,400))
self.il = CTkButton(self, image=self.on_img, text="")
self.lbl1 = CTkLabel(app, text='текст', font=('Calibri', 25),width=10, height=10, text_color='#fefae0')
self.btn1 = CTkButton(app, text='Начать', font=('Arial', 20), command=show_page1, text_color='#fefae0', width=150,
height=50, fg_color='#bc6c25', border_color='#fefae0', border_width=2, hover_color='#d4a373')
def show(self):
hide_all()
self.lbl1.place(x=40,y=230)
self.btn1.place(x=260,y=380)
def hide(self):
self.lbl1.place_forget()
self.btn1.place_forget()
page1 = Page1()
page1.show()
app.mainloop()
I tried to add self and Page 1 in super().init() but it didnt help.