为什么我的 python 桌面宠物程序在没有检测到错误的情况下尝试 运行 它时不执行任何操作?

why won't my python desktop pet program do anything when i try to run it when it has no errors detected?

Here's the link to the tutorial I followed.

当我尝试从 IDLE 中 运行 它时,它只显示 RESTART:

C:\Users\USER\Downloads\pythonpetashy.py 什么都不做

我在 Windows 上使用 Python 3.10.4

这是代码:

import random
import tkinter as tk
import pyautogui
x = 1400
cycle = 0
check = 1
idle_num = [1,2,3,4]
popo_num = [13,15]
angy_num = [10,11,12]
walk_left = [5,6,7]
walk_right = [8,9,14]
event_number = random.randrange(1,3,1)
impath = r"C:\Users\USER\Downloads\desktop project"

#transfer random no. to event
def event(cycle,check,event_number,x):
    if event_number in idle_num:
        check = 0
        print('idle')
        window.after(400,update,cycle,check,event_number,x) #no. 1,2,3,4 = idle
    elif event_number in popo_num:
        check = 1
        print('idle to popo')
        window.after(100,update,cycle,check,event_number,x) #no. 13,15 = idle to popo
        
    elif event_number in walk_left:
        check = 3
        print('walking towards left')
        window.after(100,update,cycle,check,event_number,x)#no. 5,6,7 = walk towards left
    
    elif event_number in walk_right:
        check = 4
        print('walking towards right')
        window.after(100,update,cycle,check,event_number,x)#no. 8,9,14 = walk towards right
    
    elif event_number in angy_num:
        check = 2
        print('angy')
        window.after(100,update,cycle,check,event_number,x)#no. 10,11,12 = angy

#make the gif work
def gif_work(cycle,frames,event_number,first_num,last_num) :
    if cycle < len(frames) -1:
        cycle+=1
    else:
        cycle = 0
        event_number = random.randrange(first_num,last_num+1,1)
    return cycle, event_number
def update(cycle,check,event_number,x):
    #idle
    if check ==0:
        frame = idle[cycle]
        cycle ,event_number = gif_work(cycle,idle,event_number,1,9)

    #idle to popo
    elif check ==1:
        frame = idle_to_popo[cycle]
        cycle ,event_number = gif_work(cycle,idle_to_popo,event_number,1,9)

    #angy
    elif check == 2:
        frame = angy[cycle]
        cycle ,event_number = gif_work(cycle,angy,event_number,1,9)

    #walk toward left
    elif check == 3:
        frame = walk_positive[cycle]
        cycle, event_number = gif_work(cycle,walk_positive,event_number,1,9)
        x -= 3

    #walk towards right
    elif check == 4:
        frame = walk_negative[cycle]
        cycle, event_number = gif_work(cycle,walk_positive,event_number,1,9)
        x -= -3
        window.geometry('100x100+'+str(x)+'1050')
        label.configure(image=frame)
        window.after(1,event,cycle,check,event_number,x)

window = tk.Tk()

#call ashy's action .gif to an array
idle = [tk.PhotoImage(file=impath+'\idleme.gif',format = 'gif -index %i' %(i)) for i in range(8)]#idle gif, 8 frames
idle_to_popo = [tk.PhotoImage(file=impath+'\idletopopo.gif',format = 'gif -index %i' %(i)) for i in range(13)] #idle to popo gif, 13 frames
angy = [tk.PhotoImage(file= r"C:\Users\USER\Downloads\desktop project\angyme.gif",format = 'gif -index %i' %(i)) for i in range(15)]#angy me gif, 15 frames
walk_positive = [tk.PhotoImage(file=impath+'\walkingleft.gif',format = 'gif -index %i' %(i)) for i in range(13)]#walking left gif, 13 frames
walk_negative = [tk.PhotoImage(file=impath+'\walkingright.gif',format = 'gif -index %i' %(i)) for i in range(13)]#walking right gif, 13 frames

#window configuration
window.config(highlightbackground='black')
window.overrideredirect(True)
window.wm_attributes('-transparentcolor','black')
label = tk.Label(window,bd=0,bg='black')
label.pack()

#loop the program
window.after(1,update,cycle,check,event_number,x)
window.mainloop()

我对 Python 编程世界完全陌生,所以我想尝试制作一个更复杂的程序对我来说有点雄心勃勃。我遵循了教程所说的一切,但我不知道为什么它不会做任何事情,因为没有检测到任何错误。不可否认,我确实低估了制作这样一个程序的复杂性,但它应该是一份礼物,所以我真的希望它能奏效。

关于它应该做什么的一些解释,基本上它应该打开一个透明的 window 我制作的 GIF 会像普通桌面宠物一样出现并随机移动。

如果人们使用相同的教程并遇到相同的问题,我建议您放弃学习本教程并改用 this one。特别是如果你像我一样是新手,那就更简单了:)祝你今天愉快,感谢所有试图提供帮助的人!!