Tkinter, custom widget and label updates

后端 未结 2 1963
闹比i
闹比i 2020-12-12 05:42

Description

I want to make a custom \"Table Widget\" for Tkinter and so far it\'s almost as I want.

The problem I have is that

2条回答
  •  孤城傲影
    2020-12-12 06:27

    I have only found that you have to use "StringVar()'s" in order to update the labels.

    This is not a true statement. You can update the attributes of any widget with the config / configure method. Starting with your first example, it would look like this:

    myLabel = Label(root, text='myText')
    myLabel.pack()
    myLabel.configure(text='new text')
    

    And, in your final example:

    table.getRow[0][0].configure(text='new text') 
    

    As for the bonus question, yes, it's possible.You can bind any code you want to a label just as you can any other widget, and in addition to bindings on keys and mouse buttons, you can bind on gaining and losing focus.

提交回复
热议问题