[英]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
?现在
textvariable
和variable
有什么区别?
variable
and textvariable
are similar in concept, in that both represent variable data. variable
和textvariable
在概念上相似,都代表可变数据。
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
的情况下,它主要与Entry
和Label
小部件一起使用,它是一个将显示为文本的变量。 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
的情况下,它主要用于Checkbutton
和Radiobutton
小部件,它表示小部件持有的值。 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.