Install python and PyQt4 on Windows with Eclipse

1.     Download and install package

Ø  Eclipse download eclipse-jee-indigo-SR2-win32.zip

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32.zip

After download, unzip the eclipse. Eclipse noneed install

 

Ø  Python download python-2.7.3.msi

http://www.python.org/getit/

After download, install python, I usedefault prefix C:\Python27

 

Ø  PyQt4 download PyQt-Py2.7-x86-gpl-4.9.1-1.exe

http://www.riverbankcomputing.co.uk/software/pyqt/download/

After download, install it with the defaultprefix

 

2.     Configure pydev in eclipse

Ø  Open eclipse, select “Help”->”Install New Software…”

Install python and PyQt4 on Windows with Eclipse_第1张图片

Ø  Click Add, add pydev with http://pydev.org/updates

Install python and PyQt4 on Windows with Eclipse_第2张图片

Ø  Select “PyDev for Eclipse”, click next

Install python and PyQt4 on Windows with Eclipse_第3张图片

Ø  Select “Window”->”Preference”

Install python and PyQt4 on Windows with Eclipse_第4张图片

Ø  Add python path to interpreters.

Install python and PyQt4 on Windows with Eclipse_第5张图片

Ø  Add PyQt4 lib path to libraries. My path is C:\Python27\Lib\site-packages\PyQt4

Install python and PyQt4 on Windows with Eclipse_第6张图片

Ø  Add PyQt4 module to Forced Builtins. For modulelist, you can use “import PyQt4”, “help(PyQt4)” to get the list

Install python and PyQt4 on Windows with Eclipse_第7张图片

Install python and PyQt4 on Windows with Eclipse_第8张图片

Install python and PyQt4 on Windows with Eclipse_第9张图片

3.     Test environment

Create a new project, write below code

############################################

import sys

from PyQt4 import QtGui,QtCore

class MyWidget(QtGui.QWidget):

    def __init__(self, parent=None):

        QtGui.QWidget.__init__(self,parent)

        self.setFixedSize(200, 120)

        self.quit = QtGui.QPushButton("Quit", self)

        self.quit.setGeometry(62, 40, 75, 30)

        self.quit.setFont(QtGui.QFont("Times", 18,QtGui.QFont.Bold))

        self.connect(self.quit,QtCore.SIGNAL("clicked()"),

                     QtGui.qApp, QtCore.SLOT("quit()"))

 

app = QtGui.QApplication(sys.argv)

widget = MyWidget()

widget.show()

sys.exit(app.exec_())

############################################

Run it, you will see

Install python and PyQt4 on Windows with Eclipse_第10张图片

 

4.     A example - use QT designerfor python

Ø  After install PyQt, there has a tool QT Designer which can help usto create UI

Install python and PyQt4 on Windows with Eclipse_第11张图片

Ø  Open QT Designer, create a main window

Install python and PyQt4 on Windows with Eclipse_第12张图片

Ø  Add two buttons (okButton, cancelButton), two labels and two lineEdits(nameEdit,pwEdit)

Install python and PyQt4 on Windows with Eclipse_第13张图片

Ø  Use pyuic4 to convert *.ui to *.py

c:\Python27\Lib\site-packages\PyQt4>pyuic4C:\Users\Coco\Desktop\coding\eclipse_project\PyQtSample\src\PyQtSample.ui -oc:\Users\Coco\Desktop\coding\eclipse_project\PyQtSample\src\PyQtSample.py

 

Ø  Create a python project in eclipse, add PyQtSample.py to theproject. Create a new py file named main.py, add below line in main.py

############################

import sys

from PyQt4 import QtGui,QtCore

from PyQtSample import *

 

if __name__ == "__main__":

    app =QtGui.QApplication(sys.argv)

    mywidget = Ui_MainWindow()    #you need use the class name in PyQtSampleinstead

    form = QtGui.QMainWindow()

    mywidget.setupUi(form)

    form.show()

app.exec_()

##############################

Then you can runmain.py to check the window show out

Install python and PyQt4 on Windows with Eclipse_第14张图片

 Useful link

http://blog.donews.com/limodou/archive/category/qtpyqt

http://hi.baidu.com/buptyoyo/item/6fcf351fe8d074f164eabf29

http://blog.csdn.net/wescom/article/details/4727114

http://www.cs.usfca.edu/~afedosov/qttut/

 

你可能感兴趣的:(eclipse,windows,python,qt,import,download)