#ui.py,通過ui設計師制作後直接轉換為ui.py腳本
# -*- coding: utf-8 -*-
from pyqt4 import qtcore, qtgui
try:
_fromutf8 = qtcore.qstring.fromutf8
except attributeerror:
_fromutf8 = lambda s: s
class ui_form(object):
def setupui(self, form):
form.setobjectname(_fromutf8("form"))
form.resize(400, 300)
self.retranslateui(form)
qtcore.qmetaobject.connectslotsbyname(form)
def retranslateui(self, form):
form.setwindowtitle(qtgui.qapplication.translate("form", "form", none, qtgui.qapplication.unicodeutf8))
#main.py,可視化ui.py
from pyqt4 import qtcore, qtgui, qt
from ui import *
class mainwindow(qtgui.qmainwindow):
def __init__(self,parent=none):
qtgui.qwidget.__init__(self,parent)
self.ui=ui_form()
self.ui.setupui(self)
#視窗居中顯示
desktop =qtgui.qapplication.desktop()
width = desktop.width()
height = desktop.height()
self.move((width - self.width())/2, (height - self.height())/2)
self.setmousetracking(true)
if __name__ == "__main__":
import sys
app = qtgui.qapplication(sys.argv)
myapp=mainwindow()
myapp.show()
app.exec_()