ボタンの色を変える
2017/02/04
Python2.7.10, PySide1.2.2
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, *argv, **keywords ):
super(MyMainWindow,self).__init__(*argv,**keywords)
self.btn = QtGui.QPushButton('Button', self)
self.btn.clicked.connect(self.changeColor)
self.btn.move(20, 20)
def changeColor(self):
col = QtGui.QColorDialog.getColor()
s = 'background-color: %s;' % col.name()
self.btn.setStyleSheet(s)
def main():
app = QtGui.QApplication(sys.argv)
w = MyMainWindow()
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()