PyQt Basic
#pyuic4 student.ui ----> For create python code from 'student.ui' file.
#pyuic4 student.ui > stud.py -----> For create python code from 'student.ui' file and save into file 'stud.py'.
#vim stud.py ---> Open 'stud.py' file and edit and add some lines.
#python stud.py ----> for run python file 'stud.py'
------------ BEFORE EDIT stud.py -------------
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Sat Jul 25 19:00:30 2009
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.submit_b = QtGui.QPushButton(self.centralwidget)
self.submit_b.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.submit_b.setObjectName("submit_b")
self.clear_b = QtGui.QPushButton(self.centralwidget)
self.clear_b.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.clear_b.setObjectName("clear_b")
self.cancel_3 = QtGui.QPushButton(self.centralwidget)
self.cancel_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.cancel_3.setObjectName("cancel_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.submit_b.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.clear_b.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.cancel_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))
-------- AFTER EDIT stud.py -----------
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Fri Jul 24 12:28:57 2009
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):#creating our class by inheriting 'QtGui.QMainWindow'. ----> 1
def __init__(self): # constructor. ---->2
self.widget=QtGui.QMainWindow() #Creating object of class 'QtGui.QMainWindow' for window or screen. ----> 3
self.setupUi(self.widget) #calling method 'setupUi' by passing object of winodw or screen. ----> 4
def setupUi(self, MainWindow):#method for setup user interface by placing each widgets on window or Screen.
MainWindow.setObjectName("MainWindow")#'MainWindow' is the object we created in the constructor.
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)#'self'means object of this class 'Ui_MainWindow'.
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.pushButton_3.setObjectName("pushButton_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.fun)# 'self.fun' -->pointer to signal handling function 'fun',. ----> 11
def fun(self): ----> 12
print "hello"
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)#all code for connect must before this line.
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))
import sys #for import OS(Operating Systems) system functions. ----> 5
if __name__ == "__main__": ----> 6
app=QtGui.QApplication(sys.argv) # in 'argv' by default contain our program name. ----> 7
obj=Ui_MainWindow() #creating object 'obj' of our application class 'Ui_MainWindow'. ----> 8
obj.widget.show() # to show all widgets in the our application object 'obj'. ----> 9
sys.exit(app.exec_()) ----> 10
----------------------------------------------
#pyuic4 student.ui ----> For create python code from 'student.ui' file.
#pyuic4 student.ui > stud.py -----> For create python code from 'student.ui' file and save into file 'stud.py'.
#vim stud.py ---> Open 'stud.py' file and edit and add some lines.
#python stud.py ----> for run python file 'stud.py'
------------ BEFORE EDIT stud.py -------------
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Sat Jul 25 19:00:30 2009
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.submit_b = QtGui.QPushButton(self.centralwidget)
self.submit_b.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.submit_b.setObjectName("submit_b")
self.clear_b = QtGui.QPushButton(self.centralwidget)
self.clear_b.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.clear_b.setObjectName("clear_b")
self.cancel_3 = QtGui.QPushButton(self.centralwidget)
self.cancel_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.cancel_3.setObjectName("cancel_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.submit_b.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.clear_b.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.cancel_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))
-------- AFTER EDIT stud.py -----------
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Fri Jul 24 12:28:57 2009
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):#creating our class by inheriting 'QtGui.QMainWindow'. ----> 1
def __init__(self): # constructor. ---->2
self.widget=QtGui.QMainWindow() #Creating object of class 'QtGui.QMainWindow' for window or screen. ----> 3
self.setupUi(self.widget) #calling method 'setupUi' by passing object of winodw or screen. ----> 4
def setupUi(self, MainWindow):#method for setup user interface by placing each widgets on window or Screen.
MainWindow.setObjectName("MainWindow")#'MainWindow' is the object we created in the constructor.
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)#'self'means object of this class 'Ui_MainWindow'.
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.pushButton_3.setObjectName("pushButton_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.fun)# 'self.fun' -->pointer to signal handling function 'fun',. ----> 11
def fun(self): ----> 12
print "hello"
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)#all code for connect must before this line.
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))
import sys #for import OS(Operating Systems) system functions. ----> 5
if __name__ == "__main__": ----> 6
app=QtGui.QApplication(sys.argv) # in 'argv' by default contain our program name. ----> 7
obj=Ui_MainWindow() #creating object 'obj' of our application class 'Ui_MainWindow'. ----> 8
obj.widget.show() # to show all widgets in the our application object 'obj'. ----> 9
sys.exit(app.exec_()) ----> 10
----------------------------------------------
No comments:
Post a Comment