ui设计:
设计好了,直接生成下py,之所以生成py是为了写代码的时候,IDE能够自动识别对象和函数,比较方便。
C:\Users\Administrator>pyuic4 -o pic.py Pic.ui
业务代码:
这个里边有个重要的初始化过程,super 是集成父类的属性,能够直接调用我们ui设计界面对应的py文件的信息。
#!/usr/bin/env Python
#coding: utf-8
from pic import Ui_MainWindow
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys,os
class Baby(QMainWindow,Ui_MainWindow):
def __init__(self,parent=None):
super(Baby,self).__init__(parent)
self.setupUi(self)
QObject.connect(self.pushButton_5, SIGNAL("clicked()"), self.change_show_laolaolaoye)
QObject.connect(self.pushButton_3, SIGNAL("clicked()"), self.change_show_yeyenainai)
QObject.connect(self.pushButton_4, SIGNAL("clicked()"), self.change_show_jiujiujiuma)
QObject.connect(self.pushButton_2, SIGNAL("clicked()"), self.change_show_tangtang)
QObject.connect(self.pushButton, SIGNAL("clicked()"), self.change_show_babamama)
QObject.connect(self.pushButton_6, SIGNAL("clicked()"), self.change_show_yangzai)
def change_show_babamama(self):
self.label_2.setPixmap(QPixmap("img/babamama.png"))
def change_show_yeyenainai(self):
self.label_2.setPixmap(QPixmap("img/yeyenainai.png"))
def change_show_jiujiujiuma(self):
self.label_2.setPixmap(QPixmap("img/jiujiujiuma.png"))
def change_show_tangtang(self):
self.label_2.setPixmap(QPixmap("img/tangtang.png"))
def change_show_yangzai(self):
self.label_2.setPixmap(QPixmap("img/laolao.png"))
def change_show_laolaolaoye(self):
self.label_2.setPixmap(QPixmap("img/laolaolaoye.png"))
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Baby()
form.show()
app.exec_()
实际效果:(呵呵,图片很可爱吧~~~)