2

My code:

my_var = tk.StringVar()

m_var2 = tk.StringVar()

my_entry1 = ttk.Entry(root, width=16, textvariable=my_var)

my_radio1 = ttk.Radiobutton(root, text="1", variable=my_var2)

Now what is the difference between textvariable and variable ?

TheEagle
  • 5,808
  • 3
  • 11
  • 39
Abhimanyu Sharma
  • 858
  • 1
  • 9
  • 17
  • Each type of widget defines its own set of options that can be specified; there's no reason to expect them to be the same for all widgets. Actually, Radiobuttons do have a `textvariable=` option (in addition to the `variable=` option that you're already using): it's an alternative to the `text=` option, that sets (and automatically updates) the button's label according to a Var's conteents. – jasonharper Jan 18 '21 at 14:41

1 Answers1

1

variable and textvariable are similar in concept, in that both represent variable data.

In the case of textvariable, which is mostly used with Entry and Label widgets, it is a variable that will be displayed as text. When the variable changes, the text of the widget changes as well.

In the case of variable, which is mostly used for Checkbutton and Radiobutton widgets, it represents the value that the widget holds. For example, you may have radio buttons with the text "Yes" and "No", but the actual values may be 1 and 0. In this case the variable represents the value of the widget.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685