小编sup*_*310的帖子

PyQt5 弹出窗口

我正在尝试使用 PyQt5 构建一个应用程序,当QListWidget双击a 中的项目时,该应用程序有一个辅助窗口“弹出” 。

这是代码:

import sys
from PyQt5.QtWidgets import QWidget, QListWidget, QListWidgetItem, QLabel, QPushButton, QApplication


class exampleWidget(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        listWidget = QListWidget(self)
        listWidget.itemDoubleClicked.connect(self.buildExamplePopup)

        names = ["Jack", "Chris", "Joey", "Kim", "Duncan"]

        for n in names:
            QListWidgetItem(n, listWidget)

        self.setGeometry(100, 100, 100, 100)
        self.show()

    @staticmethod
    def buildExamplePopup(item):
        name = item.text()
        exPopup = examplePopup(name)
        exPopup.setGeometry(100, 200, 100, 100)
        exPopup.show()


class examplePopup(QWidget):
    def __init__(self, name):
        super().__init__()

        self.name = name

        self.initUI()

    def initUI(self):
        lblName = QLabel(self.name, self)

if …
Run Code Online (Sandbox Code Playgroud)

popup python-3.x pyqt5

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

popup ×1

pyqt5 ×1

python-3.x ×1