Files
TransPyC/ViperQtHelloWorld/App/main.py

58 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# ViperQtHelloWorld - vqt6 的第一个示例
#
# 创建一个 Qt6 窗口:
# - 标题: "vqt6 Hello"
# - 大小: 400x300
# - 居中文本: "你好Viper"
# - 一个按钮: "退出"(点击关闭应用)
#
# 使用 vqt6 (Viper 的 Qt6 绑定) 创建窗口
# ============================================================
import t
import c
import vqt6
import w32.win32console as w32cmd
pagecode: t.CDefine = 65001
@t.CExport
def main() -> int:
w32cmd.SetConsoleOutputCP(pagecode)
w32cmd.SetConsoleCP(pagecode)
print("[vqt6] 正在创建 QApplication...")
# 1. 创建 QApplication
app: vqt6.QApplication = vqt6.QApplication([])
print("[vqt6] 正在创建窗口...")
# 2. 创建主窗口
window: vqt6.QWidget = vqt6.QWidget()
window.setWindowTitle("vqt6 Hello")
window.resize(400, 300)
window.setGeometry(100, 100, 400, 300)
# 3. 创建居中文本标签
label: vqt6.QLabel = vqt6.QLabel("你好Viper", window)
label.setAlignment(vqt6.QT_ALIGN_CENTER)
# 4. 创建退出按钮
button: vqt6.QPushButton = vqt6.QPushButton("退出", window)
# 5. 显示窗口
window.show()
print("[vqt6] 窗口已显示,进入事件循环")
print("[vqt6] 关闭窗口以退出程序")
# 6. 进入事件循环
ret: int = app.exec()
print(f"[vqt6] 应用退出,返回码: {ret}")
return ret