热门

最新

红包

立Flag

投票

同城

我的

发布
jackchuanqi
传奇开心果编程
2 年前
truejackchuanqi

温度转换应用程序示例(一)
beeware官方文档中有这样一个代码示例:一个简单的温度转换应用程序,使用了beeware的GUI库toga进行开发。下面是我对beeware官方文档示例代码添加的注释说明,帮助读者加深对这个示例代码的阅读理解。

```python
import toga
from toga.style.pack import COLUMN, LEFT, RIGHT, ROW, Pack

# 创建应用构建函数
def build(app):
# 创建三个Box组件作为容器
c_box = toga.Box()
f_box = toga.Box()
box = toga.Box()

# 创建两个文本输入框组件
c_input = toga.TextInput(readonly=True)
f_input = toga.TextInput()

# 创建三个标签组件
c_label = toga.Label("Celsius", style=Pack(text_align=LEFT))
f_label = toga.Label("Fahrenheit", style=Pack(text_align=LEFT))
join_label = toga.Label("is equivalent to", style=Pack(text_align=RIGHT))

# 创建计算按钮
def calculate(widget):
try:
c_input.value = (float(f_input.value) - 32.0) * 5.0 / 9.0
except ValueError:
c_input.value = "???"

button = toga.Button("Calculate", on_press=calculate)
(未完待续)

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
Linux Boot Sequence.
立即登录