- 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.
推薦閱讀
- OpenStack Cloud Computing Cookbook(Third Edition)
- 零基礎玩轉區塊鏈
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- 實戰低代碼
- 零基礎學MQL:基于EA的自動化交易編程
- Learning OpenStack Networking(Neutron)
- Linux:Embedded Development
- Java 9 Programming By Example
- 計算語言學導論
- 深入理解Java虛擬機:JVM高級特性與最佳實踐
- Java Web動態網站開發(第2版·微課版)
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- C/C++代碼調試的藝術
- Java服務端研發知識圖譜
- C語言從入門到精通(微視頻精編版)