Python Forum
[Tkinter] TkInter toggle Label on/off
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] TkInter toggle Label on/off
#1
How can i get a TkInter Label to toggle on off? the toggle on works the label isnt visable upon start and then appears when the checkbutton is pressed (=1), however when the button is pressed again (=0)the label remains.

def STIC_Sel():
    STIC_Sel_State = var1.get()
    if (STIC_Sel_State == 1):
            print("Test STIC Selected")
            IPT_Display_STIC = Label(IPT, text=Output_IP_Address_STIC, anchor=W)
            IPT_Display_STIC_Window = canvas_IPT.create_window(150, 160, anchor = 'sw', window = IPT_Display_STIC)
    else:
            print("STIC Not Selected")
var1 = IntVar()
IPT_Test_STIC = Checkbutton(IPT, text = "STIC", justify=LEFT,width=15, indicatoron=0,
                                variable = var1, command=STIC_Sel)
IPT_Test_STIC_Window = canvas_IPT.create_window(20, 165, anchor = 'sw', window = IPT_Test_STIC)

I have tried

def STIC_Sel():
    STIC_Sel_State = var1.get()
    if (STIC_Sel_State == 1):
            print("Test STIC Selected")
            IPT_Display_STIC = Label(IPT, text=Output_IP_Address_STIC, anchor=W)
            IPT_Display_STIC_Window = canvas_IPT.create_window(150, 160, anchor = 'sw', window = IPT_Display_STIC)
    else:
            print("STIC Not Selected")
            IPT_Display_STIC = Label(IPT, text="Not Selected For Test", anchor=W)
            IPT_Display_STIC_Window = canvas_IPT.create_window(150, 160, anchor = 'sw', window = IPT_Display_STIC)
But this just generates a label on top of the previous one
Reply
#2
there is a lift and lower command that I have use in the past, but never tried it on label.
It's worth a try.

FYI: The best tkinter documentation is here: http://infohost.nmt.edu/tcc/help/pubs/tk...index.html
Reply
#3
there was also a grid_forget()

import tkinter

root = tkinter.Tk()

lbl = tkinter.Label(root, text='label1')
lbl.grid(column=0, row=0)

lbl2 = tkinter.Label(root, text='label2')
lbl2.grid(column=1, row=0)

tkinter.Button(root, text='Remove', command=lambda:lbl.grid_forget()).grid(column=3, row=1)
tkinter.Button(root, text='Restore', command=lambda:lbl.grid(column=0, row=0)).grid(column=3, row=2)
root.mainloop()
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 406 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,480 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  [Tkinter] Updating Tkinter label using multiprocessing Agusms 6 3,053 Aug-15-2022, 07:10 PM
Last Post: menator01
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,669 Jun-26-2022, 06:26 PM
Last Post: menator01
  tkinter toggle buttons not working Nu2Python 26 6,773 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 4,920 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter: Image to Label Maryan 10 5,118 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I extend a label widget? TurboC 2 2,732 Oct-13-2020, 12:15 PM
Last Post: zazas321
  Tkinter: How to assign calculated value to a Label LoneStar 7 3,757 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  changing tkinter label from thread nanok66 3 7,215 Jun-07-2020, 01:37 AM
Last Post: nanok66

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020