pycharm+pyqt6配置

1、pip install pyqt6 pyqt6-toools

2、pycharm配置

      配置:designer

Program::D:\Python39\Lib\site-packages\qt6_applications\Qt\bin\designer.exe

Working directory: $ProjectFileDir$

  配置:pyuic6.exe

Program::D:\Python39\Scripts\pyuic6.exe

Arguments:$FileName$ -o $FileNameWithoutExtension$.py

Working directory: $ProjectFileDir$

举个例子:

import sys
from PyQt6.QtWidgets import (QApplication, QWidget, QLabel,
                             QLineEdit, QMessageBox, QPushButton)
from PyQt6.QtCore import QCoreApplication

# 主窗体
app = QApplication(sys.argv)  # 创建应用对象
LoginWindow = QWidget()  # 构造登陆窗口
LoginWindow.setWindowTitle('登陆窗口')  # 窗口标题
LoginWindow.resize(300, 180)  # 窗口大小

# 姓名Label
name_Label = QLabel(LoginWindow)  # 放置在登陆窗口上
name_Label.setText('姓名')  # 设置显示文本
name_Label.move(60, 40)  # 设置位置

# 输入姓名文本框
name_Edit = QLineEdit(LoginWindow)  # 放置在登陆窗口上
name_Edit.move(100, 36)  # 设置位置

# 密码Label
pass_Label = QLabel(LoginWindow)  # 放置在登陆窗口上
pass_Label.setText('密码')  # 设置显示文本
pass_Label.move(60, 80)  # 设置位置

# 输入密码文本框
pass_Edit = QLineEdit(LoginWindow)  # 放置在登陆窗口上
pass_Edit.move(100, 76)  # 设置位置
pass_Edit.setEchoMode(QLineEdit.EchoMode.Password)  # 设置输入密码不可见


# 登陆函数
def end_event():
    if name_Edit.text() == "":
        QMessageBox.about(LoginWindow, '登陆', '请输入姓名')
    elif pass_Edit.text() == "":
        QMessageBox.about(LoginWindow, '登陆', '请输入密码')
    else:
        QMessageBox.about(LoginWindow, '登陆', name_Edit.text() + ' 欢迎登陆')


# 登陆按钮
end_Btn = QPushButton('登陆', LoginWindow)
end_Btn.clicked.connect(end_event)  # 绑定登陆函数
end_Btn.move(60, 120)

# 退出按钮
exit_Btn = QPushButton('退出', LoginWindow)
exit_Btn.clicked.connect(QCoreApplication.instance().quit)  # 绑定退出事件
exit_Btn.move(160, 120)

LoginWindow.show()  # 显示窗口
sys.exit(app.exec())  # 进入消息循环

相关推荐

  1. nginx配置IPV6

    2024-07-16 10:38:05       34 阅读
  2. 6 Zookeeper 配置说明

    2024-07-16 10:38:05       26 阅读
  3. zs6d配置-2

    2024-07-16 10:38:05       25 阅读
  4. zs6d配置-1

    2024-07-16 10:38:05       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 10:38:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 10:38:05       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 10:38:05       58 阅读
  4. Python语言-面向对象

    2024-07-16 10:38:05       69 阅读

热门阅读

  1. js中! 、!!、?.、??、??=的用法及使用场景

    2024-07-16 10:38:05       21 阅读
  2. AP9185内置 MOS 管升压型恒流驱动芯片

    2024-07-16 10:38:05       24 阅读
  3. matlab实现绘制矢量图

    2024-07-16 10:38:05       27 阅读
  4. 实车部署 TARE 入门教程

    2024-07-16 10:38:05       27 阅读
  5. git环境编译升级

    2024-07-16 10:38:05       27 阅读
  6. Ubuntu系统和硬件问题

    2024-07-16 10:38:05       25 阅读