Home > Enterprise >  Hide Elements in Tkinter
Hide Elements in Tkinter

Time:11-24

Hope you're doing very well. I'm using Tkinter designer and Tkinter for the GUI of a program. But I have spent a whole day on a single problem, how to hide text on Canvas? I have tried many ways and this one is only the one that is acceptable.

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)

But this also throws an error type object 'Text' has no attribute 'tk' Please help, sorry for bad English and Thanks in advance.

CodePudding user response:

I think you can find answer to your question on this post here: link to post.

CodePudding user response:

If you want to hide a text item in a canvas, use 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')
  • Related