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

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.

主站蜘蛛池模板: 崇文区| 宁都县| 绩溪县| 南充市| 香港 | 旺苍县| 广饶县| 乌海市| 长顺县| 鲁山县| 石狮市| 仲巴县| 新乡市| 贡嘎县| 贵溪市| 犍为县| 宽甸| 遂昌县| 瑞丽市| 广昌县| 双流县| 油尖旺区| 柳河县| 玉环县| 河间市| 凤台县| 宁都县| 吉安市| 蒙城县| 锡林浩特市| 云安县| 雷波县| 临夏县| 安国市| 牡丹江市| 安丘市| 道孚县| 社会| 南宁市| 溧阳市| 邯郸县|