城墙下的一颗大石榴 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 欧姆龙plc枕式包装机 ST编程
  • ¥15 为啥快手广告联盟的广告这么难出来
  • ¥15 k8s集群重启后,kubelet一直报systemctl restart kubelet.service "Failed to delete cgroup paths"
  • ¥15 微信小程序构建工具类发布到npm,install后报错
  • ¥15 amesim液压仿真问题
  • ¥15 MATLAB优化设计
  • ¥15 ANN预测模型 200大米
  • ¥20 优秀学生的问题 oj java
  • ¥15 scratch-gui 如何集成进 react native
  • ¥15 把全局悬浮窗改为局内悬浮窗