0% found this document useful (0 votes)
24 views25 pages

Python GUI Programming With Py Side

The document provides an overview of Python GUI programming using PySide, highlighting the differences between CLI and GUI, and discussing various Python GUI libraries. It emphasizes the advantages of using Qt/PySide, outlines installation steps, and introduces basic programming concepts such as SIGNAL/SLOT mechanisms. The document concludes with suggestions for creating applications and improving user experience while maintaining performance.

Uploaded by

Neonai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views25 pages

Python GUI Programming With Py Side

The document provides an overview of Python GUI programming using PySide, highlighting the differences between CLI and GUI, and discussing various Python GUI libraries. It emphasizes the advantages of using Qt/PySide, outlines installation steps, and introduces basic programming concepts such as SIGNAL/SLOT mechanisms. The document concludes with suggestions for creating applications and improving user experience while maintaining performance.

Uploaded by

Neonai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python GUI programming with

PySide
Speaker: BigLittle
Date: 2013/03/04
CLI vs. GUI
CLI (Command Line Interface) GUI (Graphical User Interface)
• Take less resources. • Easier for user to view and
• User have much more control your application.
control of their system. • Ability of multitasking.
• Only need to execute few
line to perform a task.
About Python + GUI
• Some GUI library for Python:
• Tkinter - Python's standard GUI package. (Tcl/Tk)
• wxPython - A Python extension module that wraps wxWidgets library.
• PyQt4 - A Python binding of the cross-platform GUI toolkit Qt.
• PySide - A Python binding of the cross-platform GUI toolkit Qt.

• Qt & wxWidgets are both well known C++ GUI library:


• They are free and open source.
• They are cross-platform and support Unicode.
• They have full documentation and community support.
Why Qt / PySide?
• Pros:
• It’s NOT MFC style.
• Easy to build up by QtDesigner or text coding.
• Intuitive SIGNAL / SLOT mechanism.
• Supports I18N. (Internationalization)
• LGPL. (GNU Lesser General Public License)
• The API is more Pythonic.

• Cons:
• Qt is not written in standard C++ library.
• Application size is big.
• blabla……
I don’t are, and you?
Before Starting…
• Install Python (What?!)
• [Link]
• User should note the compatibility between version 2.7.x and 3.x.

• Install Qt
• [Link]
• The latest ersio is 5.0. It’s too e for e... =.=

• Install PySide
• [Link]
• Current version is 1.1.2, but most references on web is for 1.0.7.
A Simple Program
• [Link] object oriented programming styles

Just so easy!
A Simple Program cont’d
• [Link]

Import PySide module here.


A Simple Program cont’d
• [Link]

Inherit lass QMainWindow

set it’s title then show itself.


A Simple Program cont’d
• [Link]

Contains the main event loop.


Create MyWindow instance
A Simple Program cont’d
• [Link]

Actually, the easiest way may be:

app = QApplication([Link])
main = QMainWindow()
[Link] First GUI
[Link]()
[Link](app.exec_())

Trigger when execute [Link].


Where Is Other Stuff?
• Just like a HD, you must format it then you can put in your data.
• HD  Current Window
• Format  QLayout
• Data  QWidget

• QLayout and QWidget are the


most basic classes that make up
your GUI.

QMainWindow is a subclass of QWidget.


Right figure shows the default configuration.
QLayout
• I fa t, you do ’t eed to start fro QLayout itself. There are
many pre-designed layout. Use them directly should be enough.

QHBoxLayout

QGridLayout
QVBoxLayout

QFormLayout
QWidget
• Example Think: What’s the layout setting
in the QGroupBox?
Let’s Put Something On )t
How To Activate It?
• No you ha e a ski of your appli atio . Let’s ake it a ti ated.
For example, push Big utton then type Bigger on the editor.
trigger response
• In Qt, trigger & response are called SIGNAL & SLOT
SIGNAL / SLOT
• [Link]([Link])
• The advantage of SIGNAL / SLOT is the caller does not have to
know anything about the receiver and vice versa.
• Any function could be a SLOT.
• One can connect several SLOT to a SIGNAL and vice versa.

• A common usage: Real-time check for input contents


Exercise…
• Try to modify the simple program to MD5 Encrypter.
Exercise… cont’d
• You need import hashlib first
Use Advanced Module
• Matplotlib - A Python plotting library. (Based on PySide!)
• SciPy - An open source library of scientific tools for Python.
• VTK - Visual Tool Kit (TVTK, Mayavi)
Much Better Than Excel…
• Source code: [Link]
Something To Be Continued
• Decorations:
• Take ad a tages of groups, ta s, tooltips, …, et .
• Add some icons, sounds or visual effects.

• Maintains:
CurveExpert
• Debug, debug and debug. (PyInstaller)

• Packing/Release:
• PyInstaller - Cross platform
• cx_Freeze - Cross platform
• py2exe - Window only

BitTorrent
(py2exe)
Create Your Own GUI App!
• Model-View-Controller
• Automation Tool
• Distributed Programming
• Database Management
• Multimedia
• CAD Software
• Embedded System
• Web Application
• Games
• ……
Summary
• GUI programming could help you interactively control the
application and report visualized final data. Every programmer
should familiar with its basic concept.

• Programming in PySide = Programming in OOP. All components


in library can be easily adapted and modified. Try to use them as
much as possible.

• There are a y sple did fu tio s like graphi s, a i atio ,


drag & drop…, et . for GUI progra i g. You a i pro e the
user experience by these, but remember to pay more attention
on the performance of your application.
References
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
• [Link]
Thanks for your attention.

You might also like