希望你做得很好。我正在使用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)
但這也會引發錯誤型別物件“文本”沒有屬性“tk”請幫忙,抱歉英語不好,并提前致謝。
uj5u.com熱心網友回復:
如果要隱藏畫布中的文本項,請使用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')
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/365033.html
