通过单击按钮更改变量; Python 3.4

Changing a variable through a button click; Python 3.4

好的,我有一些代码可以用于我自己制作的点击器小游戏。我试图在按钮上打印原始成本,然后,当我单击该按钮时,按钮上的成本会更新,并且成本实际上会增加给用户。看一看。

这些都是我的变量。

click = 0
mult = 1
dcp1 = 0
autoclickers = 0
mines = 0
grandmas = 0
doubleclickcost = 5
autoclickercost = 7
minecost = 10
grandmacost = 15
costmultiplyer = 1.3

顺便说一句,我只是取出了有问题的代码。这是处理奶奶费用的代码。

purchaseGrandmaButton = Button(master, text="Purchase Grandma - " + str(grandmacost) + " Clicks", command = purchaseGrandmaCommand)
purchaseGrandmaButton.pack()

所以我想做的是让按钮更新按钮显示奶奶成本的金额。http://puu.sh/hOWdf/0970e92276.png <- Before I buy a grandma. http://puu.sh/hOWfy/6dad5b94bb.png <- 在我买了奶奶之后。按钮上的 number/cost 没有改变,我想要它,但我不知道如何改变。

您可以在每次单击时重新配置按钮的文本:

grandmacost = 15

def purchaseGrandmaCommand():
    global grandmacost
    grandmacost +=15
    global purchaseGrandmaButton
    purchaseGrandmaButton.config(text="Purchase Grandma - " + str(grandmacost) + " Clicks"