通过单击按钮更改变量;Python3.4

2024-10-03 23:26:31 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我有一些代码,我正在为自己制作一个小游戏。我试着在按钮上打印原始成本,然后,当我点击按钮时,按钮上的成本会更新,用户的成本会增加。看一看。你知道吗

这些都是我的变量。你知道吗

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<;-在我买祖母之前。http://puu.sh/hOWfy/6dad5b94bb.png<;-在我买了一个奶奶之后。按钮上的数字/成本不变,我也希望如此,但我不知道怎么做。你知道吗


Tags: 代码用户lthttppngsh按钮成本
1条回答
网友
1楼 · 发布于 2024-10-03 23:26:31

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

grandmacost = 15

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

相关问题 更多 >