我沒有顯示在Python廣告這個園藝計劃的Qt4PyQt的,小部件
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
color = QtGui.QColor(99, 0, 0)
class colorButton(QtGui.QWidget):
def __init__(self, args):
QtGui.QWidget.__init__(self,args)
self.setGeometry(150, 22, 50, 50)
self.setStyleSheet("QWidget { background-color: %s }" % color.name())
class ColorDialog(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(40, 40, 220, 100)
self.setWindowTitle('ColorDialog')
button=colorButton(self)
app = QtGui.QApplication(sys.argv)
cd = ColorDialog()
cd.show()
app.exec_()
的intrpreter不給我任何錯誤,但「有色」窗口小部件不顯示。爲什麼? 謝謝
類colorButton(QtGui.QWidget)缺少一個「:」,但這樣會產生一個SyntaxError ... – miku 2010-01-04 16:15:09
在Python中,類名一般用大寫字母開頭。 – 2010-01-04 22:32:00