【发布时间】:2023-02-04 22:18:29
【问题描述】:
我制作了一个 tkinter 国家猜谜游戏女巫工作正常但需要时间才能运行。所以我在一个单独的文件中为它制作了一个带有循环动画的加载屏幕。我找不到一种方法来先运行加载屏幕,然后在加载屏幕上的动画仍在运行时运行游戏。
加载屏幕代码:
`from tkinter import*
from time import*
import os
import random
run = 0
loads = True
dotnum = 0
def task():
sleep(2)
root.destroy()
root = Tk()
root.title("Loading...")
root.geometry("1280x720")
Background = PhotoImage(file = "Images\Loadscreen.png")
Loaders = PhotoImage(file = "Images\Loader.gif")
image = Label(root,width=1000,height=500,image=Background)
image.place(x=0, y=0, relwidth=1, relheight=1)
frameCnt = 16
frames = [PhotoImage(file='Images\Loader.gif',format = 'gif -index %i' %(i)) for i in range(frameCnt)]
def update(ind):
frame = frames[ind]
ind += 1
if ind == frameCnt:
ind = 0
loadanim.configure(image=frame)
root.after(100, update, ind)
loadanim = Label(root, bg = "black")
loadanim.place(x = 450, y = 450)
root.after(0, update, 0)
root.mainloop()`
【问题讨论】: