Search the Community
Showing results for tags 'pyqt'.
-
0. Why PyQt? When ever one plans the development of an application, an important consideration is the language one will use to code it. Some of the things that can play a role are: Will the application have a GUI Will the application be cross-platform or platform specific. Do you want a high-level or low-level language (or something in between) Nowadays, it is very common to want to develop applications that have a user friendly GUI. For windows only applications C# is a great option. Visual C# Express is available for free from Microsoft and has an easy to use GUI builder. However, if one wants to code a cross-platform application C# is no longer such an attractive option. While The Mono Project aims to allow for C# applications to be cross-platform there are many things missing. C++, a very popular and poweful language, is a cross platform language, but unfortunately it does not have a standard GUI builder. What one must do is decide on a package to use for the GUIs. Some populat options are WxWidgets and Qt. However, C++ is a low-level language. If one prefers a high-level language to stay away from all the complications of programming in C++, Python is a great option. Like C++, it is a cross-platform language. Also like C++, it does not have a standard GUI package. Because Qt is one of the more powerful and expansive GUI packages for C++ and has been ported to python, PyQt is one of the best options for developing GUI applications with Python. The official PyQt introduction can be found here: http://www.riverbankcomputing.co.uk/software/pyqt/intro Or particulat interest is: As mentioned in the official Why PyQt?, Python is an interpreted language, whereas C++ is a compiled language. This can mean slower applications. When speed is a crucial issue, one might choose C++ despite having to deal with the low-level language implications. I. Getting Started Here a few things that you need to get started with PyQt. Python 2.6 http://www.python.org/download/ PyQt4 for python 2.6 http://www.riverbankcomputing.co.uk/software/pyqt/download I started learning pyqt from this book: http://www.qtrac.eu/pyqtbook.html Even if you cannot buy the book or find it at a library it is still useful to get this: http://www.qtrac.eu/pyqtbook26.zip Inside you will find sample code and more importantly Make PyQt (makepyqt.pyw) Make PyQt is a python program that will turn the ui files made using the Qt Designer. II. A PyQt IDE While it is possible to develop pyqt programs with only a text editor, there are many conveniences that once can take advantage of. I would at least recommend using the Qt Designer (comes with PyQt) and Make PyQt (makepyqt.pyw) to generate the code needed for the GUIs. Combined with something like Programmer's Notepad this works very nicely. However, for those who prefer to use an IDE, there is a good option. The Eric4 IDE is a great tool that helps keep one's projects in order. I will be using it for the examples. III. Example (Updated example, comming soon) PyQt programs begin as follows: from PyQt4.QtCore import * from PyQt4.QtGui import * import ui_ppremain PyQt4.QtCore and PyQt4.QtGui are the basic modules that we need to make PyQt Programs. import ui_ppremain, imports the file ui_ppremain.py, which is what makepyqt.pyw outputs when you choose to build in the directory where you have your ui files. and the code that executes the program as follows: app = QApplication(sys.argv) mw = MainWindow() mw.show() app.exec_() the code for the main window would be: class MainWindow(QMainWindow, ui_ppremain.Ui_MainWindow): def __init__(self,parent=None): super(MainWindow,self).__init__(parent) self.setupUi(self) self.updateUi() self.romname=""; def updateUi(self): self.nameLabel.text="ROM Name:" One thing to notice is that indentation is important in python. Structure is provided through indentation rather than braces as in other languages. More concrete examples to come later. Feel free to ask questions.
- 7 replies
-
- programming
- pyqt
-
(and 1 more)
Tagged with: