Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GUI Programming with Python (PyQt 5)

GUI Programming with Python (PyQt 5)

PyQt 5 is the Python binding for Qt 5, developed by Riverbank Computing. This talk covers its very basics, and offers some extra information about general GUI programming.

9dafad54b5b4f360b7aae5f482bc1c91?s=128

Tzu-ping Chung

August 28, 2014
Tweet

More Decks by Tzu-ping Chung

Other Decks in Programming

Transcript

  1. GUI Programming with Python

  2. Me • Call me TP • Follow @uranusjr • https://uranusjr.com

    2
  3. None
  4. www. .com

  5. http://macdown.uranusjr.com

  6. GUI Programming with Python

  7. None
  8. None
  9. Are you sure?

  10. Web application?

  11. Why • Native features • Nice Appearance • Easier access

    11 Why Not • Platform-specific • Difficult to learn • Deployment
  12. GUI frameworks are not really Python

  13. Native behaviour matters

  14. http://qt-project.org

  15. Qt • Pronounced as “cute” • Cross-platform • C++ (plus

    code generator) 15
  16. Application Framework • Core utility types • GUI components •

    Multimedia, networking, etc. 16
  17. PyQt • Riverbank Computing • Qt 5 + Python 2/3

    • Qt 4 + Python 2 • GPL or commercial 17 PySide • Nokia → community • Qt + Python 2 • LGPL
  18. Installation • Windows: pyqt.sourceforge.net • OS X: brew  install  pyqt5

    • Linux: Use the force package manager 18
  19. If you haven’t done it yet, it’s too late.

  20. The Run Loop 20 Launch Initialise W ait for events

    Handle events Quit
  21. Launch Initialise W ait for events Handle events Quit The

    Run Loop 21
  22. Demo #1 I’m using PyQt 5.3 on OS X. Source:

    https://gist.github.com/uranusjr/f55c8a5622c80c29732a
  23. Qt Widgets • Not covering QML today • Basic GUI

    components • “Top level” vs “Child widgets” 23
  24. Demo #2 Widgets within widgets are children of widgets. Source:

    https://gist.github.com/uranusjr/f55c8a5622c80c29732a
  25. Signals & Slots • When something happen, a signal is

    emitted • Slots can be connected to signals • When a signal emits, all slots connected to it are called 25
  26. Demo #3 Simon says: Open sesame! Source: https://gist.github.com/uranusjr/f55c8a5622c80c29732a

  27. Layouts • Horizontal, vertical, grid • Alignment, ratio, fill rule

    • Nest them to create complex layouts! 27
  28. Demo #4 Get your widgets in a row. Or a

    column. Or whatever you wish. Source: https://gist.github.com/uranusjr/f55c8a5622c80c29732a
  29. Qt Essentials • Basic modules • Core, Test • Modules

    based on other libraries • Multimedia, Network, SQL, WebKit • GUI modules • Widgets, Utility Widgets, QML, Quick 29
  30. Demo #5 Qt unleashed. Source: https://gist.github.com/uranusjr/f55c8a5622c80c29732a

  31. How Does It Work? • Qt written in C++ •

    Compiled libraries • Bindings created by SIP • Python program 31
  32. http://setanta.wordpress.com/binding-c/

  33. Usage Issues • Deployment • Platform-dependent • pyqtdeploy • Licensing

    • GPL or commercial 33
  34. PyQt • Riverbank Computing • Qt 5 + Python 2/3

    • Qt 4 + Python 2 • GPL or commercial 34 PySide • Nokia → community • Qt + Python 2 • LGPL Mostly compatible
  35. Resources • http://pyqt.sourceforge.net/Docs/PyQt5/ • http://qt-project.org/doc/qt-5/ • Learn to read (some)

    C++!! 35
  36. Don’t Like It? • IronPython, PyObjC • PyGTK+, wxPython •

    Kivy • Toga 36
  37. FIRE QUESTIONS