Tkinter variable definition, which is more desirable? Tkinter variable definition, which is more desirable? tkinter tkinter

Tkinter variable definition, which is more desirable?


Tkinter variables like StringVar are commonly used to track the change of its values or to pass them as the variable or textvariable option for creating some widgets. From the section "When to use the Variable Classes" of the page you refer to:

Variables can be used with most entry widgets to track changes to the entered value. The Checkbutton and Radiobutton widgets require variables to work properly.

Variables can also be used to validate the contents of an entry widget, and to change the text in label widgets.

So in your case the natural solution would be the second one: it looks like you want to store the result of askopenfilename() like you would do with the result of another statement, but not use it to interact with the text of a widget or track if the value of the StringVar has changed (since you are calling that function, you already know when it is going to be updated).