mam problem z moim kodem nie umiem otworzyc zdjecia w login page udaje mi sie bez problemu lecz w main app juz nie dostaje taki blad
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1967, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:\Users\folks\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
self._command()
File "C:\Users\folks\Desktop\Login\main.py", line 84, in login
main_app = MainApp()
^^^^^^^^^
File "C:\Users\folks\Desktop\Login\main.py", line 135, in __init__
CTkLabel(master=self.main_frame, text=" Password:", text_color="#616161", anchor="w", justify="left", font=("Arial Bold", 14),
File "C:\Users\folks\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\customtkinter\windows\widgets\ctk_label.py", line 104, in __init__
self._update_image()
File "C:\Users\folks\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\customtkinter\windows\widgets\ctk_label.py", line 141, in _update_image
self._label.configure(image=self._image.create_scaled_photo_image(self._get_widget_scaling(),
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1721, in configure
return self._configure('configure', cnf, kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1711, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage3" doesn't exist
a tu moj kod
import tkinter
from customtkinter import CTk, CTkLabel, CTkButton, CTkEntry, CTkFrame, CTkImage
from tkinter import Button, Tk, messagebox
from PIL import Image, ImageTk
import os
import customtkinter
from tkinter import *
from PIL import Image
class CTkMainButton(Button):
def __init__(self, master=None, bg_color=None, hover_color=None, text_color=None, **kwargs):
super().__init__(master, **kwargs)
self.bg_color = bg_color
self.hover_color = hover_color
self.text_color = text_color
self.bind("<Enter>", self.on_enter)
self.bind("<Leave>", self.on_leave)
self.update_colors()
def update_colors(self):
if self.bg_color:
self.config(bg=self.bg_color)
if self.hover_color:
self.hover_bg = self.hover_color
if self.text_color:
self.config(fg=self.text_color)
def on_enter(self, event):
self.config(bg=self.hover_bg)
def on_leave(self, event):
self.config(bg=self.bg_color)
class LoginPage:
def __init__(self, master):
self.master = master
self.master.geometry("400x350")
self.master.resizable(0, 0)
self.master.title("Loader")
username = os.getlogin()
self.email_icon_data = Image.open("email-icon.png")
self.password_icon_data = Image.open("password-icon.png")
self.email_icon = CTkImage(dark_image=self.email_icon_data, light_image=self.email_icon_data, size=(20, 20))
self.password_icon = CTkImage(dark_image=self.password_icon_data, light_image=self.password_icon_data,size=(20, 20))
self.frame = CTkFrame(master=master, width=500, height=480)
self.frame.pack_propagate(0)
self.frame.pack(expand=True, side="right")
CTkLabel(master=self.frame, text="Hello " + username + "!", text_color="#7E7E7E", anchor="w", justify="left", font=("Arial Bold", 24)).pack(anchor="w", pady=(20, 5), padx=(25, 0))
CTkLabel(master=self.frame, text="Sign in to your account", text_color="#7E7E7E", anchor="w", justify="left", font=("Arial Bold", 12)).pack(anchor="w", padx=(25, 0))
username_label_width = len("Username:") + 2
password_label_width = len("Password:") + 2
entry_width = 225
max_width = max(username_label_width, password_label_width, entry_width)
CTkLabel(master=self.frame, text=" Username:", text_color="#616161", anchor="w", justify="left",
font=("Arial Bold", 14), image=self.email_icon, compound="left").pack(anchor="w", pady=(20, 0), padx=(50, 0))
self.email_entry = CTkEntry(master=self.frame, width=max_width, fg_color="#878787", border_color="#7E7E7E", border_width=1, text_color="#000000")
self.email_entry.pack(anchor="w", padx=(55, 55))
CTkLabel(master=self.frame, text=" Password:", text_color="#616161", anchor="w", justify="left", font=("Arial Bold", 14),
image=self.password_icon, compound="left").pack(anchor="w", pady=(20, 0), padx=(50, 0))
self.password_entry = CTkEntry(master=self.frame, width=max_width, fg_color="#878787", border_color="#7E7E7E",
border_width=1, text_color="#000000", show="*")
self.password_entry.pack(anchor="w", padx=(55, 55))
CTkButton(master=self.frame, text="Login", fg_color="#616161", hover_color="#616161",
font=("Arial Bold", 12), text_color="#ffffff", width=225, command=self.login).pack(anchor="w",pady=(40, 0),padx=(52, 0))
def login(self):
email = self.email_entry.get()
password = self.password_entry.get()
if email == "a" and password == "a":
self.master.withdraw()
main_app = MainApp()
main_app.run_main_app()
else:
messagebox.showerror("Login Failed", "Invalid username or password!")
class MainApp:
def __init__(self):
self.root = CTk()
self.root.geometry("800x444")
self.root.resizable(0, 0)
self.root.title("Main app")
self.main_frame = CTkFrame(master=self.root, bg_color="#2B2B2B")
self.main_frame.pack(side="right", fill="both", expand=True)
self.options_frame = CTkFrame(master=self.root, bg_color="#7E7E7E")
self.options_frame.pack(side="left", fill="both", expand=False)
self.dupa_icon_data = Image.open("dupa.png")
self.dupa_icon = CTkImage(dark_image=self.dupa_icon_data, light_image=self.dupa_icon_data, size=(20, 20))
self.buttons = []
options = [
("Home", self.show_home),
("Cleaner", self.show_cleaner),
("String Remover", self.show_string_remover),
("Ip Finder", self.show_soon),
("Socjalki", self.show_socjalki),
("Settings", self.show_settings)
]
for option_text, option_function in options:
button = CTkButton(master=self.options_frame, text=option_text, fg_color="#7E7E7E", hover_color="#7E7E7E",
font=("Arial", 12), text_color="#2B2B2B", width=125,
command=lambda func=option_function: func())
button.pack(anchor="w", pady=(20, 20), padx=(20, 20))
self.buttons.append(button)
self.welcome_label = CTkLabel(master=self.main_frame, text="", text_color="#7E7E7E", font=("Arial Bold", 30))
self.welcome_label.pack(anchor="ne", pady=(0, 1), padx=(0, 250))
self.welcome_label_small = CTkLabel(master=self.main_frame, text="", text_color="#7E7E7E", font=("Arial Bold", 15))
self.welcome_label_small.pack(anchor="ne", pady=(0, 1), padx=(0, 240))
self.welcome_discord = CTkLabel(master=self.main_frame, text="", text_color="#7E7E7E",anchor="w", justify="left", font=("Arial Bold", 25))
self.welcome_discord.pack(anchor="ne", pady=(0, 1), padx=(0, 400))
##CTkLabel(master=self.main_frame, text=" Password:", text_color="#616161", anchor="w", justify="left", font=("Arial Bold", 14),
##image=self.dupa_icon, compound="left").pack(anchor="w", pady=(20, 0), padx=(50, 0))
self.message_label = CTkLabel(master=self.main_frame, text="", text_color="#ffffff",font=("Arial", 22), bg_color="#2B2B2B")
self.message_label.pack(pady=20, padx=20)
self.show_home() # Dodane wywołanie metody show_home() po utworzeniu instancji klasy MainApp
def show_home(self):
username = os.getlogin()
self.welcome_label.configure (text="Hello " + username + "!")
self.welcome_label_small.configure(text="Welcome to our cleaner!")
self.welcome_discord.configure(text="Join our discord!")
self.show_message("")
def show_cleaner(self):
self.welcome_label.configure(text="")
self.welcome_label_small.configure(text="")
self.welcome_discord.configure(text="")
self.show_message("Cleaner")
def show_string_remover(self):
self.welcome_label.configure(text="")
self.welcome_label_small.configure(text="")
self.welcome_discord.configure(text="")
self.show_message("String Remover")
def show_soon(self):
self.welcome_label.configure(text="")
self.welcome_label_small.configure(text="")
self.welcome_discord.configure(text="")
self.show_message("Ip Finder")
def show_socjalki(self):
self.welcome_label.configure(text="")
self.welcome_label_small.configure(text="")
self.welcome_discord.configure(text="")
self.show_message("Socjalki")
def show_settings(self):
self.welcome_label.configure(text="")
self.welcome_label_small.configure(text="")
self.welcome_discord.configure(text="")
self.show_message("Settings")
def show_message(self, message):
self.message_label.configure(text=message)
def run_main_app(self):
self.root.mainloop()
if __name__ == "__main__":
root = CTk()
login_page = LoginPage(root)
root.mainloop()