城墙下的一颗大石榴 2022-05-12 18:26 采纳率: 100%
浏览 46
已结题

程序找不到问题pythonGUI界面扑克牌

在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也不行

请帮我找找问题在哪里

  • 写回答

3条回答 默认 最新

  • 溪风沐雪 2022-05-12 18:38
    关注

    你需要把扑克的图片都放到D:/FFOutput/目录里

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 5月20日
  • 已采纳回答 5月12日
  • 创建了问题 5月12日

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行