• pyqt 调用颜色选择器


    # -*- coding: utf-8 -*-
    
    from PyQt5.QtWidgets import QApplication, QPushButton, QColorDialog , QWidget
    from PyQt5.QtCore import Qt 
    from PyQt5.QtGui import QColor 
    import sys 
    
    class ColorDialog ( QWidget): 
        def __init__(self ): 
            super().__init__() 
            #颜色值
            color = QColor(0, 0, 0) 
            #位置
            self.setGeometry(300, 300, 350, 280) 
            #标题
            self.setWindowTitle('颜色选择') 
            #按钮名称
            self.button = QPushButton('Dialog', self) 
            self.button.setFocusPolicy(Qt.NoFocus) 
            #按钮位置
            self.button.move(40, 20) 
            #按钮绑定方法
            self.button.clicked.connect(self.showDialog) 
            self.setFocus()
            self.widget = QWidget(self) 
            self.widget.setStyleSheet('QWidget{background-color:%s} '%color.name()) 
            self.widget.setGeometry(130, 22, 200, 100) 
            
        def showDialog(self): 
            col = QColorDialog.getColor() 
            print(col.name(),"
    ")
            if col.isValid(): 
                self.widget.setStyleSheet('QWidget {background-color:%s}'%col.name()) 
        
    if __name__ == "__main__": 
        app = QApplication(sys.argv) 
        qb = ColorDialog() 
        qb.show()
        sys.exit(app.exec_())
  • 相关阅读:
    Solution to LeetCode Problem Set
    《Cracking the Coding Interview》读书笔记
    诗词收集——用于人文素养扫盲
    2015年清华大学计算机系考研总结
    编程知识大杂烩
    hihoCoder 1175:拓扑排序二
    Hackerrank
    Hackerrank
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9865366.html
Copyright © 2020-2023  润新知