Created
November 12, 2015 17:16
-
-
Save JokerMartini/725484f1338f635116c2 to your computer and use it in GitHub Desktop.
Pyside Pthon: A simple color picker using pyside and python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide import QtGui | |
class Example(QtGui.QWidget): | |
def __init__(self): | |
super(Example, self).__init__() | |
self.initUI() | |
def initUI(self): | |
col = QtGui.QColor(0, 0, 0) | |
# controls | |
self.colorPicker = QtGui.QPushButton("0,0,0") | |
# signals | |
self.colorPicker.clicked.connect(self.pickColorDialog) | |
# layout | |
hbox = QtGui.QVBoxLayout() | |
hbox.addWidget(self.colorPicker) | |
self.setLayout(hbox) | |
# STYLING | |
self.setStyleSheet(""" | |
QPushButton { | |
color: rgb(0,0,0); | |
font-size: 14px; | |
background-color:rgb(0,0,0) | |
} | |
""") | |
self.setGeometry(300, 300, 300, 300) | |
self.setWindowTitle('Color dialog') | |
self.show() | |
def pickColorDialog(self): | |
sender = self.sender() | |
col = QtGui.QColorDialog.getColor() | |
if col.isValid(): | |
col_str = "( {0}, {1}, {2} )".format(col.red(), col.green(), col.blue()) | |
sender.setText(col_str) | |
sender.setStyleSheet("QWidget { background-color: %s }" % col.name()) | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment