简体   繁体   English

tkinter中的变量和文本变量的区别

[英]Difference Between Variable And Textvariable in tkinter

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 ?现在textvariablevariable有什么区别?

variable and textvariable are similar in concept, in that both represent variable data. variabletextvariable在概念上相似,都代表可变数据。

In the case of textvariable , which is mostly used with Entry and Label widgets, it is a variable that will be displayed as text.textvariable的情况下,它主要与EntryLabel小部件一起使用,它是一个将显示为文本的变量。 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.variable的情况下,它主要用于CheckbuttonRadiobutton小部件,它表示小部件持有的值。 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.例如,您可能有带有文本“是”和“否”的单选按钮,但实际值可能是 1 和 0。在这种情况下, variable表示小部件的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM