# 文件名:hello_word.py
import sys
from PyQt5.Qt import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.label_1 = QLabel()
self.button_1 = QPushButton()
self.set_ui()
def set_ui(self):
self.resize(300, 300)
self.setStyleSheet("color:blue")
self.setWindowTitle("主窗口")
self.label()
self.button()
self.action()
self.show()
def label(self):
self.label_1 = QLabel(self)
self.label_1.setText("Hello")
self.label_1.move(100, 100)
def button(self):
self.button_1 = QPushButton(self)
self.button_1.setText("按下试试")
self.button_1.move(100, 200)
def action(self):
self.button_1.clicked.connect(self.push_button)
def push_button(self):
self.label_1.setText("World!")
self.label_1.adjustSize()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())
"""
1.Pycharm中从 文件>设置>项目>Python解释器 搜索并安装Nuitka
2.下载MinGW-W64 GCC-8.1.0,解压并将路径mingw64\bin添加环境变量并重启 下载地址:https://sourceforge.net/projects/mingw-w64/files/ 文件名:x86_64-win32-sjlj
3.打开Pycharm中的终端,执行命令 nuitka --mingw64 --standalone --windows-disable-console --show-progress --show-memory --plugin-enable=qt-plugins --output-dir=out hello_word.py
执行过程中可能有Nuitka-Scons:INFO: Too old gcc 'C:\\mingw64\\bin\\gcc.exe' ((8, 1, 0) < (11, 2)) ignored!等提示,按提示下载所需文件即可。
4.完成,exe文件在out\hello_word.dist中,运行一下试试。
"""