- 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.
推薦閱讀
- Learning C# by Developing Games with Unity 2020
- 劍指JVM:虛擬機實踐與性能調優
- Architecting the Industrial Internet
- SharePoint Development with the SharePoint Framework
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Rust Essentials(Second Edition)
- Python編程實戰
- Building Serverless Applications with Python
- 學習正則表達式
- Julia高性能科學計算(第2版)
- HTML 5與CSS 3權威指南(第3版·上冊)
- “笨辦法”學C語言
- QGIS 2 Cookbook
- PostgreSQL Developer's Guide
- 高性能PHP 7