예제 #1
0
import sys
import demo  # 这里是ui文件转换的文件名

from PyQt5.QtWidgets import QApplication, QMainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = QMainWindow()  # 获取主窗口mainWindow
    ui = demo.Ui_MainWindow()  # 获取demo中的组件
    ui.setupUi(mainWindow)  # 生成窗口
    mainWindow.show()  # 显示mainWindow
    sys.exit(app.exec_())  # app.exec_()运行主循环,sys.exit()可以判断程序退出并返回到主线程
예제 #2
0
import sys
import demo

from PyQt5.QtWidgets import QApplication, QMainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = QMainWindow()
    ui = demo.Ui_MainWindow()
    ui.setupUi(mainWindow)
    mainWindow.show()
    sys.exit(app.exec_())
예제 #3
0
import sys
import demo
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication,QMainWindow

if __name__ == '__main__':
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QApplication(sys.argv)        # 创建应用对象
    mainWindow = QMainWindow()          # 创建主窗口对象
    ui = demo.Ui_MainWindow()           # 实例化类对象
    ui.setupUi(mainWindow)              # 在主窗口添加控件(需传入一个参数)
    mainWindow.show()                   # 显示窗口
    sys.exit(app.exec_())               # 进入程序主循环,并通过exit函数确保主循环安全结束