20.case QDiaglog

from PyQt5.QtWidgets import QMainWindow,QWidget,QDialog,QPushButton,QApplication,QDesktopWidget,QHBoxLayout,QVBoxLayout,QFormLayout,QGridLayout,\
    QToolTip,QLabel,QLineEdit,QTextEdit,QRadioButton,QCheckBox,QComboBox,QSlider,QSpinBox,QMessageBox,QInputDialog,\
    QFontDialog,QColorDialog
from PyQt5.QtGui import QIcon,QFont,QPalette,QPixmap,QIntValidator,QDoubleValidator,QRegExpValidator
from PyQt5.QtCore import Qt,QRegExp
import sys

class DialogDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle('DialogDemo')
        self.setGeometry(500,500,300,200)

        button1 = QPushButton('选择颜色')
        button1.clicked.connect(lambda :self.getColor(label_test))
        button2 = QPushButton('选择背景')
        button2.clicked.connect(lambda: self.getColor(label_test))
        button3 = QPushButton('选择字体')
        button3.clicked.connect(lambda: self.getFont(label_test))
        label_test = QLabel('hello python')

        layout_button = QVBoxLayout()
        layout_button.addWidget(button1)
        layout_button.addWidget(button2)
        layout_button.addWidget(button3)
        layout_button.addWidget(label_test)
        self.setLayout(layout_button)

    def getFont(self,label):
        sender = self.sender()
        font, ok = QFontDialog.getFont()
        if ok:
            label.setFont(font)
    def getColor(self,label):
        sender = self.sender()
        p = QPalette()
        label.setAutoFillBackground(True)
        # if sender.text() == '选择颜色':
        #     color1 = QColorDialog.getColor()
        # if sender.text() == '选择背景':
        #     color2 = QColorDialog.getColor()
        p.setColor(QPalette.WindowText, QColorDialog.getColor())
        label.setPalette(p)
        p.setColor(QPalette.Window, QColorDialog.getColor())
        label.setPalette(p)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = DialogDemo()
    main.show()

    sys.exit(app.exec_())


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值