Python GUI卡程序= TclError:图像<img name=""/>不存在

时间:2018-03-20 00:31:37

标签: python tkinter

我正在制作一个GUI程序,以便从GUI中的文件显示卡片的图像,通过点击gui中的按钮随机选择并显示卡片。我的代码全部完成但是我遇到了一个我从未见过的错误,称为TclError:image&#34; DECK / 13c.gif&#34;不存在。 该文件夹与程序位于同一目录中。该文件是一个标题为DECK的gif文件,文件中的卡片标记为10个钻石,因此它是DECK / 10d.gif,但它表示它不存在。提前致谢

from tkinter import *
import random

class GUI(Frame):

    def __init__(self):
        Frame.__init__(self)
        self.master.title("Random Images")
        self.grid()
        self._cardImage = None
        self._backOfCard = PhotoImage(file = 'DECK/b.gif')
        self._imageLabel = Label(self, image = self._backOfCard)
        self._imageLabel.grid(row = 0, column = 0, rowspan = 3)

        self._randButton = Button(self, text = "Show Random Card", 
                                  command = self._getCard())
        self._randButton.grid(row = 0, column = 1, columnspan = 2)
        if self._cardImage != None:
            self._cardImage = Label(self, image = self._getCard())
            self._cardImage.grid(row = 0, column = 0, rowspan = 3)

    def _getCard(self):
        rank = random.randint(1,13)
        suit = ['s','h','d','c']
        suit = random.choice(suit)
        strOfCard = "DECK/" + str(rank) + suit + ".gif"
        self._cardImage = strOfCard
        return self._cardImage

def main():
    GUI().mainloop()


main()

编辑:这是错误:

\__init__.py", line 2293, in __init__
    (widgetName, self._w) + extra + self._options(cnf))

TclError: image "DECK/11s.gif" doesn't exist

0 个答案:

没有答案