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

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.

主站蜘蛛池模板: 大渡口区| 加查县| 吉木乃县| 宜阳县| 广丰县| 昌平区| 增城市| 平阳县| 鲜城| 绥阳县| 西丰县| 通城县| 天津市| 武陟县| 西和县| 兴安盟| 溆浦县| 平昌县| 赤城县| 江山市| 张家界市| 汶川县| 岐山县| 中方县| 秦安县| 新绛县| 封丘县| 三亚市| 社旗县| 临海市| 定州市| 浑源县| 华安县| 望江县| 灵石县| 二手房| 法库县| 苏尼特左旗| 甘南县| 遂川县| 保德县|