# _*_ coding:utf-8 _*_
import sys
from PyQt4 import QtCore,QtGui
class Example(QtGui.QWidget):
    def __init__(self):
        super(Example,self).__init__()
        self.initUI()
    def initUI(self):
        self.button=QtGui.QPushButton('Dialog',self)
        self.button.setFocus()
        self.button.move(20,20)
        self.connect(self.button,QtCore.SIGNAL('clicked()'),self.showDialog)
        self.setFocus()
        self.label=QtGui.QLineEdit(self)
        self.label.setMaximumWidth(20)
        self.label.move(130,22)

        self.widget=QtGui.QWidget(self)
        self.widget.setStyleSheet("QWidget{background-color:red}" )

        grid=QtGui.QGridLayout()

        grid.addWidget(QtGui.QPushButton(u'我是个按钮'),1,1)
        grid.addWidget(QtGui.QPushButton(u'我是个按钮'), 0, 0)

        #self.setLayout(grid)
        self.widget.setLayout(grid)
        self.widget.move(150,22)
        self.resize(100,100)
        #self.widget.setGeometry(150, 22, 100, 150)
        self.buuton2=QtGui.QPushButton(u'设置背景色',self)
        self.connect(self.buuton2,QtCore.SIGNAL('clicked()'),self.changeBackground)
        self.buuton2.move(220,22)

        self.setWindowTitle('InputDialog')
        self.setGeometry(300,300,350,80)

    def showDialog(self):
        text,ok=QtGui.QInputDialog.getText(self,'Input Dialog','Enter your name');
        if ok:
            self.label.setText(str(text))
    def changeBackground(self):
        col=QtGui.QColorDialog.getColor()
        if col.isValid():
            self.widget.setStyleSheet("QWidget { background-color: %s }"
                                      % col.name())

    def showDialog(self):

        font, ok = QtGui.QFontDialog.getFont()
        if ok:
            self.label.setFont(font)

    def showDialog(self):

        filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home')
        fname = open(filename)
        data = fname.read()
        self.textEdit.setText(data)


app=QtGui.QApplication(sys.argv)
ex=Example()
ex.show()
app.exec_()
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
相关资源
相似解决方案