在 Tkinter 中隐藏元素
Hide Elements in Tkinter
希望你做得很好。我正在使用 Tkinter designer
和 Tkinter 作为程序的 GUI。但是我在一个问题上花了一整天,如何隐藏Canvas上的文字?试了很多方法,只有这个可以接受
canvas.place(x = 0, y = 0)
subtext = canvas.create_text(
343.0,
179.0,
anchor="nw",
text="What made you here?",
fill="#000000",
font=("Roboto Condensed", 89 * -1),
)
subtext = Text
def Jokes():
joke = random.choice(jokes)
print(joke)
subtext.pack_forget(self=subtext)
但这也会引发错误type object 'Text' has no attribute 'tk' 请帮忙,抱歉英语不好,提前致谢。
如果要隐藏 canvas 中的文本项,请使用 Canvas.itemconfigure(tagOrId, state='hidden')
:
subtext = canvas.create_text(
343.0,
179.0,
anchor="nw",
text="What made you here?",
fill="#000000",
font=("Roboto Condensed", 89 * -1),
)
# below line overwrite subtext
# it should not be called
#subtext = Text
def Jokes():
joke = random.choice(jokes)
print(joke)
# hide the text item
canvas.itemconfigure(subtext, state='hidden')
希望你做得很好。我正在使用 Tkinter designer
和 Tkinter 作为程序的 GUI。但是我在一个问题上花了一整天,如何隐藏Canvas上的文字?试了很多方法,只有这个可以接受
canvas.place(x = 0, y = 0)
subtext = canvas.create_text(
343.0,
179.0,
anchor="nw",
text="What made you here?",
fill="#000000",
font=("Roboto Condensed", 89 * -1),
)
subtext = Text
def Jokes():
joke = random.choice(jokes)
print(joke)
subtext.pack_forget(self=subtext)
但这也会引发错误type object 'Text' has no attribute 'tk' 请帮忙,抱歉英语不好,提前致谢。
如果要隐藏 canvas 中的文本项,请使用 Canvas.itemconfigure(tagOrId, state='hidden')
:
subtext = canvas.create_text(
343.0,
179.0,
anchor="nw",
text="What made you here?",
fill="#000000",
font=("Roboto Condensed", 89 * -1),
)
# below line overwrite subtext
# it should not be called
#subtext = Text
def Jokes():
joke = random.choice(jokes)
print(joke)
# hide the text item
canvas.itemconfigure(subtext, state='hidden')