官术网_书友最值得收藏!

Using and updating

Since these variables are objects, we cannot assign to them a statement like label_text = "Hello World!". Instead, each variable exposes a get and set method. Let's have a play with these in the interactive shell:

>>> from tkinter import *
>>> win = Tk()
>>> sv = StringVar()
>>> sv
<tkinter.StringVar object at 0x05F82D50>
>>> sv.get()
''
>>> sv.set("Hello World!")
>>> sv.get()
'Hello World!'
>>> sv.set(sv.get() + " How's it going?")
>>> sv.get()
"Hello World! How's it going?"

These variables are passed to widgets inside their keyword arguments upon creation (or at a later stage, using configure). The keyword arguments expecting these special variables will usually end in var.  In the case of a label, the argument is textvar.

主站蜘蛛池模板: 莒南县| 临沂市| 从化市| 霸州市| 万山特区| 三门县| 遂平县| 马龙县| 阿图什市| 金寨县| 岱山县| 武穴市| 宜川县| 东安县| 宜良县| 兰溪市| 宁城县| 井陉县| 景谷| 永川市| 资阳市| 永新县| 石嘴山市| 施甸县| 开封县| 德令哈市| 宜昌市| 通道| 章丘市| 定结县| 东至县| 始兴县| 广南县| 莎车县| 定州市| 和林格尔县| 陆丰市| 石屏县| 黑水县| 威远县| 乡城县|