初始化

This commit is contained in:
rxy
2026-05-18 11:33:59 +08:00
commit b22e46dd60
20 changed files with 1440 additions and 0 deletions

26
demo/mvvm/view_model.py Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ViewModel 层。
ViewModel 连接界面操作与业务数据:按钮点击后不直接操作界面,
而是修改 ModelModel 再通过事件通道通知 View 刷新。
"""
from mvvm.model import *
class MainWinVM(object):
"""主窗口 ViewModel保存主窗口需要的数据模型和按钮事件逻辑。"""
def __init__(self):
# 创建日志内容 Model。
# 主题 "log_to_view" 表示:这个 Model 的变化要通知日志 View。
self.model_log = StringModel('log_to_view', '启动日志')
def event_log_yes(self):
"""Yes 按钮点击事件:写入一条 yes 日志。"""
self.model_log.value = 'log: yes!!!'
def event_log_no(self):
"""No 按钮点击事件:写入一条 no 日志。"""
self.model_log.value = 'log: no~~~'