Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python3中将元素传递给多个函数_Python_Python 3.x - Fatal编程技术网

在Python3中将元素传递给多个函数

在Python3中将元素传递给多个函数,python,python-3.x,Python,Python 3.x,因此,我正在开发一个程序,在一副牌中洗牌,并在用户点击“交易”按钮时返回一张牌的图片。但是我试图将fileName从deal函数传递到refreshImages函数,我似乎无法让它工作。想知道是否有人能告诉我怎么做,并解释为什么。谢谢 def deal(self): card = self.deck.deal() self.stateLabel["text"] = str(card) fileName = "DECK/" + str(card.rank) + card.s

因此,我正在开发一个程序,在一副牌中洗牌,并在用户点击“交易”按钮时返回一张牌的图片。但是我试图将
fileName
deal
函数传递到
refreshImages
函数,我似乎无法让它工作。想知道是否有人能告诉我怎么做,并解释为什么。谢谢

def deal(self):
    card = self.deck.deal()
    self.stateLabel["text"] = str(card)
    fileName = "DECK/" + str(card.rank) + card.suit[0] + ".gif"
    self.refreshImages(fileName)
    if len(self.deck) == 0:
        self.dealBtn["state"] = "disabled"

def shuffle(self):
    card = self.deck.shuffle()
    fileName = "DECK/" + str(card.rank) + card.suit[0] + "gif"
    self.refreshImages(fileName)
    if len(seld.deck) == 0:
        self.dealBtn["state"] = "disabled"

def refreshImages(self):
    """Updates the images in the window."""
    self.image = PhotoImage(file = fileName)
    self.cardLabel1["image"] = self.image

由于您的
deal
方法使用文件名作为参数调用
refreshImages
方法,因此
refreshImages
方法应使用此类参数声明;否则调用方的局部变量
fileName
将不会神奇地传递给被调用的方法:

def refreshImages(self, fileName):
    """Updates the images in the window."""
    self.image = PhotoImage(file = fileName)
    self.cardLabel1["image"] = self.image

我一开始是这么做的,但我猜我输入错了文件名。。。我是个白痴。不过非常感谢。