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

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.

主站蜘蛛池模板: 阜宁县| 佛坪县| 巨鹿县| 科尔| 阿克苏市| 贵州省| 吉林市| 鲁山县| 湖南省| 汉阴县| 阳东县| 梁山县| 娄底市| 三台县| 平乐县| 綦江县| 垫江县| 衡阳县| 福清市| 芦山县| 漳浦县| 靖宇县| 万安县| 虎林市| 滨海县| 宜宾市| 抚宁县| 黎平县| 海伦市| 重庆市| 鸡东县| 江口县| 沭阳县| 项城市| 开江县| 东宁县| 博罗县| 曲周县| 宜黄县| 岑溪市| 潞西市|