在PyQt5中显示消息框可以使用QMessageBox类。以下是一个简单的例子:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Message box example')
self.showMessageBox()
def showMessageBox(self):
QMessageBox.information(self, 'Information', 'This is an information message box')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
在这个例子中,我们创建了一个简单的窗口,并在窗口中显示了一个信息消息框。您可以通过调用QMessageBox的静态方法(如information、question、warning等)来显示不同类型的消息框。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/929977.html