- Tkinter GUI Programming by Example
- David Love
- 120字
- 2021-08-27 18:49:08
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.
推薦閱讀
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及MySQL應(yīng)用教程(第2版)
- Node.js 10實(shí)戰(zhàn)
- 自然語(yǔ)言處理實(shí)戰(zhàn):預(yù)訓(xùn)練模型應(yīng)用及其產(chǎn)品化
- 在最好的年紀(jì)學(xué)Python:小學(xué)生趣味編程
- C#程序設(shè)計(jì)實(shí)訓(xùn)指導(dǎo)書
- Visual C++數(shù)字圖像模式識(shí)別技術(shù)詳解
- 深入淺出Android Jetpack
- Mathematica Data Analysis
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲(chóng)案例實(shí)戰(zhàn)全流程詳解(入門與提高篇)
- Angular開(kāi)發(fā)入門與實(shí)戰(zhàn)
- 深入分布式緩存:從原理到實(shí)踐
- Python High Performance Programming
- Building Machine Learning Systems with Python(Second Edition)
- C#面向?qū)ο蟪绦蛟O(shè)計(jì)(第2版)
- PostgreSQL 12 High Availability Cookbook