【发布时间】:2016-06-09 15:14:09
【问题描述】:
我有一个 QMainWindow 有一个按钮,当点击这个按钮时,另一个小部件会弹出。此小部件有一个按钮,单击此按钮时会弹出警报消息。当我在该消息按钮上按“确定”时,只有 QMessageBox 正在关闭,小部件仍处于打开状态。当我按该消息按钮上的“确定”时,我想关闭该小部件。我不知道我该怎么做。这是我的代码;
from PyQt5.QtWidgets import (QMessageBox,QApplication, QWidget, QToolTip, QPushButton,
QDesktopWidget, QMainWindow, QAction, qApp, QToolBar, QVBoxLayout,
QComboBox,QLabel,QLineEdit,QGridLayout,QMenuBar,QMenu,QStatusBar,
QTextEdit,QDialog,QFrame,QProgressBar,QHBoxLayout
)
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import QIcon,QFont,QPixmap,QPalette,QWindow
from PyQt5.QtCore import QCoreApplication, Qt,QBasicTimer, QTimer,QPoint
import PyQt5.QtWidgets,PyQt5.QtCore
import time,random,subprocess,sys,json
class cssden(QMainWindow):
def __init__(self):
super().__init__()
self.mwidget = QMainWindow(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setFixedSize(600,500)
#Other widget button
self.owidget = QPushButton(self)
self.owidget.clicked.connect(self.second_widget)
self.show()
#other widget
#I want to destroy this widget when I press 'OK' on the QMessageBox
def second_widget(self):
self.w_window = QWidget()
self.w_window.setGeometry(650,300,600,300)
self.w_window.setStyleSheet("background-color: lightblue")
self.w_button = QPushButton(self.w_window)
self.w_button.setText("Alert")
self.w_button.clicked.connect(self.alert)
self.w_window.show()
#alert from second widget
def alert(self):
QMessageBox.about(self.w_window,"Alert","Alert message")
app = QApplication(sys.argv)
app.setStyleSheet("QMainWindow{background-color: rgb(30,30,30);border: 1px solid black}")
ex = cssden()
sys.exit(app.exec_())
我试图连接它们(QMessageBox 的“确定”按钮和最后一个小部件),但我做得不好,我真的很困惑。
【问题讨论】:
标签: python python-3.4 qwidget pyqt5 qmessagebox