- 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.
推薦閱讀
- Spring Boot開發與測試實戰
- Learning Real-time Processing with Spark Streaming
- Magento 2 Development Cookbook
- GitLab Repository Management
- Learning ArcGIS Pro
- Android 應用案例開發大全(第3版)
- Python數據挖掘與機器學習實戰
- Learning Data Mining with R
- 用戶體驗增長:數字化·智能化·綠色化
- Spring Boot Cookbook
- Windows內核編程
- Creating Stunning Dashboards with QlikView
- Mastering Linux Security and Hardening
- The Professional ScrumMaster’s Handbook
- Android Studio開發實戰:從零基礎到App上線 (移動開發叢書)