如何在 Tkinter Python 中安排事件

问题描述 投票:0回答:0

我想使用打印黑屏的 tkinter 创建代码,打印徽标,然后再次打印黑屏。我正在尝试使用 after() 但我只是黑屏,它加载了一段时间,然后进入灰色屏幕。

from tkinter import *
import customtkinter as ctk
import pyautogui
from PIL import Image,ImageTk

screenWidth, screenHeight = pyautogui.size()
root = ctk.CTk()
root.title("FreeBank")
root.geometry(f"{screenWidth}x{screenHeight}")


def initialScreenSettings(root):
    root.config(bg="black")
    root.iconbitmap("icon.ico")
    print('main')



def loadingScreen(root):
    print('loading screen start')
    canvas = Canvas(root, width = screenWidth, height = screenHeight)
    canvas.pack() 
    img = PhotoImage(file="FreeBank_Logo.png")
    canvas.create_image(20,20, anchor=NW, image=img)
    print('loading screen end')

initialScreenSettings(root)
root.after(5000, loadingScreen(root))
root.after(10000, initialScreenSettings(root))

root.mainloop()

这是我的代码。

我尝试将 root.mainloop 添加到函数 loadingScreen 中:

def loadingScreen(root):
    print('loading screen start')
    canvas = Canvas(root, width = screenWidth, height = screenHeight)
    canvas.pack() 
    img = PhotoImage(file="FreeBank_Logo.png")
    canvas.create_image(20,20, anchor=NW, image=img)
    print('loading screen end')
    root.mainloop()

这只是立即打印徽标,没有别的。 我知道代码确实通过 loadingScreen 运行,因为我添加了 print() 语句进行测试并且它们出现了。

tkinter scheduled-tasks customtkinter
© www.soinside.com 2019 - 2024. All rights reserved.