小编lfs*_*ndo的帖子

Python PyQt5 QMessageBox无法打开

当我按infoButton时,我正在尝试打开一个消息框.它运行infoDialogue方法,因为它打印"我在这里",但它不打开infoBox.我错过了什么?

我正在使用python 3.5和PyQt5

谢谢!

这是代码:

import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QToolTip, QPushButton, QMessageBox)
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QIcon, QFont

class mainWindow(QWidget):

    def __init__(self, screenWidth, screenHeight, windowWidth=400, windowHeight=400):      
        super().__init__()
        self.screenWidth = screenWidth
        self.screenHeight = screenHeight              
        self.windowWidth = windowWidth
        self.windowHeight = windowHeight
        self.initUI()


    def initUI(self):
        QToolTip.setFont(QFont('SansSerif', 10))
        self.setToolTip('ToolTip Widget')

        exitButton = QPushButton('Exit', self)        
        exitButton.setToolTip("<b>Wish to Exit?</b>")        
        exitButton.resize(exitButton.sizeHint())       
        exitButton.move(100, 100)      
        exitButton.clicked.connect(QCoreApplication.instance().quit)           

        infoButton = QPushButton('Info', self) # Button that calls infoDialogue()
        infoButton.setToolTip('<b>ToolTip</b>')
        infoButton.resize(infoButton.sizeHint())
        infoButton.move(100, 200)
        infoButton.clicked.connect(self.infoDialogue)      

        positionX = (self.screenWidth …
Run Code Online (Sandbox Code Playgroud)

python python-3.x qmessagebox pyqt5

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

标签 统计

pyqt5 ×1

python ×1

python-3.x ×1

qmessagebox ×1