Getting tkinter labels to update when variable changes

后端 未结 1 1079
执笔经年
执笔经年 2021-01-27 18:38

I\'m trying to build an app with pythons tkinter module.

Currently I\'m trying to get a labels displayed text to change when a radiobutton is selected. I have the labels

相关标签:
1条回答
  • 2021-01-27 18:53

    In this code, Label updates every click of Radiobutton using command option of Radiobutton and Label's text variable.

    from Tkinter import *
    
    def radio_action():
        value1 = var1.get()
        changeable_label['text'] = value1
    
    the_window = Tk()
    the_window.title('Example')
    
    the_window.geometry("200x150")
    
    var1 = StringVar()
    
    changeable_label = Label(the_window, text = "Null")
    button1 = Radiobutton(the_window, text = 'Button1', variable = var1,
                         value="Something", command = radio_action)
    
    changeable_label.pack(side = TOP)
    button1.pack()
    
    
    the_window.mainloop()
    

    Since I don't know your whole code, this is I can help with an example.

    0 讨论(0)
提交回复
热议问题