在Pythoncharm上一直报错,但是不知道问题在哪里.
from tkinter import * # Import all definitions from tkinter
import random
class DeckOfCardsGUI:
def __init__(self):
window = Tk()
window.title("Pick Four Cards Randomly") # Set title
self.imageList = [] # Store images for cards
for i in range(1, 53):
self.imageList.append(PhotoImage(file="FFOutput" + str(i) + ".gif"))
frame = Frame(window) # Hold four labels for cards
frame.pack()
self.labelList = [] # A list of four labels
for i in range(4):
self.labelList.append(Label(frame, image=self.imageList[i]))
self.labelList[i].pack(side=LEFT)
Button(window, text="Shuffle", command=lambda:self.shuffle).pack()
window.mainloop() # Create an event loop
# Choose four random cards
def shuffle(self):
random.shuffle(self.imageList)
for i in range(4):
self.labelList[i]["image"] = self.imageList[i]
DeckOfCardsGUI() # Create GUI
Traceback (most recent call last):
File "C:\Users\昔韭尒\AppData\Local\Programs\Python\Python310\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm 2021.3.1\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2021.3.1\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/FFOutput/cards.py", line 32, in
DeckOfCardsGUI() # Create GUI
File "D:/FFOutput/cards.py", line 11, in init
self.imageList.append(PhotoImage(file="FFOutput" + str(i) + ".gif"))
File "C:\Users\昔韭尒\AppData\Local\Programs\Python\Python310\lib\tkinter_init.py", line 4093, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "C:\Users\昔韭尒\AppData\Local\Programs\Python\Python310\lib\tkinter_init.py", line 4038, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "FFOutput1.gif": no such file or directory
加了lambda也不行
请帮我找找问题在哪里