首页 > 其他分享 >PyQT5之QDialog

PyQT5之QDialog

时间:2024-06-13 15:33:54浏览次数:19  
标签:__ self PyQT5 QDialog dialog import button

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class QDialogDemo(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('QDialog实例')
        self.resize(300, 300)

        self.button = QPushButton(self)
        self.button.setText('弹出对话框')
        self.button.move(50, 50)
        self.button.clicked.connect(self.showDialog)

    def showDialog(self):
        dialog = QDialog()
        button = QPushButton("确定", dialog)
        button.clicked.connect(dialog.close)
        button.move(50, 50)
        dialog.setWindowTitle('对话框')
        dialog.setWindowModality(Qt.ApplicationModal)

        dialog.exec()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QDialogDemo()
    main.show()
    sys.exit(app.exec_())

标签:__,self,PyQT5,QDialog,dialog,import,button
From: https://www.cnblogs.com/jackchen28/p/18245971

相关文章

  • PyQT5之多页面切换
    fromPyQt5.QtWidgetsimportQApplication,QWidget,QStackedLayout,QVBoxLayoutfromPyQt5.QtWidgetsimportQPushButton,QComboBox,QSizePolicyimportsysif__name__=='__main__':app=QApplication(sys.argv)my_widget=QWidget()my_w......
  • 【Python】成功解决ModuleNotFoundError: No module named ‘PyQt5‘
    【Python】成功解决ModuleNotFoundError:Nomodulenamed‘PyQt5’ 下滑即可查看博客内容......
  • PyQT5之QSS基础/子控件选择器
    fromPyQt5.QtWidgetsimport*importsysclassBasicQCSS(QWidget):def__init__(self):super().__init__()self.setWindowTitle("QSS样式/子控件选择器")btn1=QPushButton(self)btn1.setText("按钮1")b......
  • PyQT5窗口样式设置
    importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*classWindowPattern(QMainWindow):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)self.resize(500,300)self......
  • PyQT5之设置窗口控件风格
    设置窗口控件风格QApplication.setStyle(...)窗口可以显示三种风格:['windowsvista','Windows','Fusion']importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*#print(QStyleFactory.keys())classWindow......
  • PyQT5之多窗口交互
    方法一:不适用信号与槽MultiWin.py文件"""多窗口交互--不适用信号与槽"""importsysfromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*fromPyQt5.QtWidgetsimport*fromDateDialogimportDateDialogclassMultiWindow1(QWidget):def__init__......
  • PyQT5之为槽函数传递参数
    方法一:lambda表达式传递参数fromPyQt5.QtCoreimport*fromPyQt5importQtCorefromPyQt5.QtWidgetsimport*importsysclassLambdaSlotArg(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle("使用Lambda表达式为槽函......
  • PyQT5信号与槽的连接
    方法一:fromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*importsysclassAutoSignalSlot(QWidget):def__init__(self):super().__init__()self.setWindowTitle("信号与槽自动连接")self.resize(300,100)self.okB......
  • PyQT5信号刷新时间
    importtimefromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*importsysclassBackendThread(QThread):update_date=pyqtSignal(str)defrun(self):whileTrue:data=QDateTime.currentDateTime()currentTim......
  • PyQT5之信号关闭窗口
    fromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*importsysclassWinSignal(QWidget):#定义一个信号button_clicked_signal=pyqtSignal()def__init__(self):super().__init__()self.setWindowTitle("为窗口类添加信号")......