2021年3月2日星期二

Show/Hide label by clicking on the tkinter button

I want to hide the label by clicking on the button and show the same label by clicking on the same button and I want to show those labels below the clicked button. I have tried the below code but by clicking any of the button only the collaborate label is visible in below to button2. but I want it as if I click button1 the "get started" label should appear below to button1 and if I clicked button2 the "collaborate" label should appear below to button2

import tkinter as tk    root=tk.Tk()    def label_hide_show():      global hidden      if hidden:          label1.pack(side = "top", fill = tk.BOTH)          hidden = False      else:          label1.pack_forget()          hidden=True                hidden = True    btn1 = tk.Button(root, text="Get Started", height=3,width=26,bg="White", fg="Black", command=label_hide_show)  label1 = tk.Label(root, text="Get started")            btn1.pack(side = "top", fill = tk.BOTH)    btn2 = tk.Button(root, text="Collaborate", height=3,width=26,bg="White", fg="Black", command=label_hide_show)  label1 = tk.Label(root, text="Collaborate")            btn2.pack(side = "top", fill = tk.BOTH)  

Output of the above code:

enter image description here

https://stackoverflow.com/questions/66444529/show-hide-label-by-clicking-on-the-tkinter-button March 03, 2021 at 01:47AM

没有评论:

发表评论