Проблемы с областью действия кнопки загрузки заставки TkinterPython

Программы на Python
Anonymous
Проблемы с областью действия кнопки загрузки заставки Tkinter

Сообщение Anonymous »

Я пытаюсь создать заставку с двумя кнопками, которые либо загрузят старый проект, либо запустят новый. У меня возникли проблемы с добавлением командных функций к кнопкам «Создать» и «Загрузить» на экране-заставке, которые уничтожают экран-заставку и запускают основное приложение. Я считаю, что это из-за масштаба. Любая помощь будет полезна!
from tkinter import *
from tkinter import ttk
import time

# Splash Screen
class SplashScreen:
def __init__(self, root, callback):
self.root = root
self.callback = callback

self.splash = Toplevel(root)
self.splash.overrideredirect(True)

screen_width = self.splash.winfo_screenwidth()
screen_height = self.splash.winfo_screenheight()
splash_width = 600
splash_height = 400
x = (screen_width - splash_width) // 2
y = (screen_height - splash_height) // 2
self.splash.geometry(f"{splash_width}x{splash_height}+{x}+{y}")

self.create_content()
#self.splash.after(2000, self.close_splash)

def create_content(self):
bg_frame = Frame(self.splash, bg="#4361ee")
bg_frame.pack(fill=BOTH, expand=True)

logo_label = Label(bg_frame, text="Let's Go", font=("Arial", 80), bg="#4361ee", fg="white")
logo_label.pack(pady=(50, 20))

#Buttons on Splash Screen Need Help With
new_button = Button(bg_frame, text="New Map")
new_button.pack(pady=10)

load_button = Button(bg_frame, text="Load Map")
load_button.pack(pady=10)

#app_name = Label(bg_frame, text="John's App", font=("Montserrat", 36, "bold"),
#bg="#4361ee", fg="white")
#app_name.pack(pady=10)

loading_text = Label(bg_frame, text="Loading...", font=("Open Sans", 14), bg="#4361ee", fg="white")
loading_text.pack(pady=20)

self.progress = ttk.Progressbar(bg_frame, orient=HORIZONTAL, length=300)
self.progress.pack(pady=10)
self.update_progress()

def update_progress(self):
for i in range(101):
self.progress['value'] = i
self.splash.update()
time.sleep(0.02)

def close_splash(self):
self.splash.destroy()
self.callback()

#Main Application
class MainApp():
def __init__(self, root):
self.root = root
self.root.withdraw()

SplashScreen(root, self.show_main_app)

def show_main_app(self):
self.root.deiconify()
self.root.title("Main Page")
self.root.geometry("800x600")
self.root.config(bg="#f8f9fa")

#Buttons on Main App screen
load_Button = Button(root, text="Load Map")
load_Button.place(x=315, y=480)

Save_Button = Button(root, text="Save Project")
Save_Button.place(x=315, y=440)

#Run Application
if __name__ == "__main__":

root = Tk()
app = MainApp(root)

root.mainloop()

Вернуться в «Python»