[Tkinter] TkInter toggle Label on/off - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] TkInter toggle Label on/off (/thread-12221.html) |
TkInter toggle Label on/off - MTom5 - Aug-14-2018 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 RE: TkInter toggle Label on/off - Larz60+ - Aug-14-2018 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/tkinter/web/index.html RE: TkInter toggle Label on/off - metulburr - Aug-15-2018 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() |