【发布时间】:2017-01-13 20:14:44
【问题描述】:
我是 python 新手,遇到问题时正在创建一个小游戏。我搜索了一个答案,找到了一个,但它没有用。
我正在尝试制作的游戏或多或少是 Cookie Clicker 的再创作,我正在尝试制作我在更新时获得分数的标签,而不是创建一个新标签。
from tkinter import *
import time
master = Tk()
def uiPrint():
print("")
print(click)
blankLine()
click = 0
mult = 1
dcp1 = 0
def blankLine():
for i in range(20):
print("")
def buttonCommand():
global click
global mult
click += 1*(mult)
uiPrint()
scoreCommand = Button(text=click)
scoreCommand.pack()
mainClickButton = Button(master, text="Click me!", command = buttonCommand)
mainClickButton.pack()
master.title("Cookie Clicker")
photo = PhotoImage(file=r"C:\Users\---\Desktop\Cookie.gif")
label = Label(image=photo)
label.image = photo
label.pack()
mainloop()
【问题讨论】:
-
“没用”是什么意思?你收到错误了吗?如果是这样,它很可能确切地说明了它为什么不起作用。此外,问题中代码的缩进在某些地方看起来不正确。
-
对于我在编程和识别问题方面的糟糕技能,我深表歉意,但没有错误消息,尽管它没有按照我的意愿执行。我制作了一段关于它的作用的视频:gyazo.com/378a81554232f9421efb62b81f62f272 但我只希望它在一个标签上更新,而不创建许多其他标签。
-
抱歉,您能否稍微编辑一下问题的代码部分,现在看来 uiPrint 函数没有做任何事情。您还可以在定义之前使用 click。
-
label['text'] = "Hello World"或label["image"] = new_image -
顺便说一句:或
label.config(text="Hello World")。其他小部件也是如此 - 即。mainClickButton["command"] = stop_clicking或mainClickButton.config(command=stop_clicking)
标签: python tkinter label photo tk