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

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.

主站蜘蛛池模板: 山东省| 莱州市| 黔西| 亳州市| 孟津县| 镇沅| 茶陵县| 兴化市| 元氏县| 天柱县| 永川市| 罗山县| 新建县| 苗栗县| 望奎县| 佛教| 军事| 东乌珠穆沁旗| 大埔区| 新化县| 敦煌市| 红桥区| 武义县| 湛江市| 太白县| 朔州市| 开化县| 建德市| 当涂县| 汉川市| 泸溪县| 五峰| 正蓝旗| 五台县| 格尔木市| 天镇县| 辽阳县| 敖汉旗| 大城县| 元江| 乳山市|