JonathanGardnerPyQtTutorial This is a short tutorial to get you up to speed with PyQt. It assumes some knowledge of bash, Python, and Qt. If you have questions or comments, you can send them to me at jgardner@jonathangardner.net. A (brazilian) portuguese translation is available at thanks to Rodrigo B. Abstract We will cover: Using Qt Designer to generate Qt ui files. Requirements You will need: Red Hat 8.0 with the following configuration: qt-devel RPM properly installed PyQt-devel RPM properly installed PyQt works on other systems. You should already know: How to use a text editor, and how to get that text editor to edit Python code properly. If you haven't fulfilled these requirements, you may have some trouble getting the tutorial to work. Using Qt Designer First things first. $ designer You are presented with Qt designer. I won't assume you are totally inept at using Qt Designer. Create a new widget. Add a QLineEdit. Using pyuic $ pyuic at.ui Tabs are important! $ make
Learning Python Design Patterns Through Video Lectures In my previous post about learning Python programming through video lectures I stopped at three lectures on Design Patterns. This time I continue from there. If you don't know what a Design Pattern is, think of it as a simple solution to a specific problem that occurs very frequently in software design. For example, suppose you use a bunch of unrelated pieces of code. It is a nice idea to bring the unrelated pieces of code together in a unified interface. This design pattern is called Facade. The three lectures are given by Alex Martelli who works as "Über Tech Lead" for Google. Python Design Patterns, Part I Alex briefly covers the history and main principles of Design Patterns and quickly moves to discussing Structural and Behavioral DPs in Python. Interesting ideas from the lecture: Python Design Patterns, Part II In this lecture Alex discusses behavioral patterns. Python Design Patterns, A Recap This video lecture was presented at Google Developers day.
Text Processing in Python (a book) A couple of you make donations each month (out of about a thousand of you reading the text each week). Tragedy of the commons and all that... but if some more of you would donate a few bucks, that would be great support of the author. In a community spirit (and with permission of my publisher), I am making my book available to the Python community. Minor corrections can be made to later printings, and at the least errata noted on this website. Email me at <mertz@gnosis.cx> . A few caveats: (1) This stuff is copyrighted by AW (except the code samples which are released to the public domain).
PyQt About PyQt PyQt is one of the two most popular Python bindings for the Qt cross-platform GUI/XML/SQL C++ framework (another binding is PySide). PyQt developed by Riverbank Computing Limited. Qt itself is developed as part of the Qt Project. PyQt provides bindings for Qt 4 and Qt 5. PyQt is available in two editions: PyQt4 which will build against Qt 4.x and 5.x and PyQt5 which will only build against 5.x. The latest iteration of PyQt is v5.4. PyQt Documentation Current documentation is available for PyQt4 and PyQt5. The PyQt Wiki contains more actively-updated information and examples: A collection of links to books can be found on the Books page. On this Wiki, you can find the following tutorials: A tutorial presented by Jonathan Gardner at the 2003 Northwest Linux Fest is available at JonathanGardnerPyQtTutorial. Developing with PyQt and PyKDE PyQt Applications A list of applications that use PyQt as their UI layer can be found on the Some Existing Applications page. Earlier Versions
HowTo/Sorting Original version by Andrew Dalke with a major update by Raymond Hettinger Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable. There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various manuals describing them, so I'll do so here. Sorting Basics A simple ascending sort is very easy -- just call the sorted() function. It returns a new sorted list: >>> sorted([5, 2, 3, 1, 4]) [1, 2, 3, 4, 5] You can also use the list.sort() method of a list. >>> a = [5, 2, 3, 1, 4] >>> a.sort() >>> a [1, 2, 3, 4, 5] Another difference is that the list.sort() method is only defined for lists. Key Functions Starting with Python 2.4, both list.sort() and sorted() added a key parameter to specify a function to be called on each list element prior to making comparisons. For example, here's a case-insensitive string comparison: Operator Module Functions
BeginnersGuide/NonProgrammers Python for Non-Programmers If you've never programmed before, the tutorials on this page are recommended for you; they don't assume that you have previous experience. If you have programming experience, also check out the BeginnersGuide/Programmers page. Books Each of these books can be purchased online but is also available as free textual, website, or video content. Automate the Boring Stuff with Python - Practical Programming for Total Beginners by Al Sweigart is "written for office workers, students, administrators, and anyone who uses a computer to learn how to code small, practical programs to automate tasks on their computer." You can find many free Python books online. Interactive Courses These sites give you instant feedback on programming problems that you can solve in your browser. CheckiO is a gamified website containing programming tasks that can be solved in Python 3. Resources for Younger Learners Tutorials and Websites Tutorial Aggregators / lists Apps Videos Email Academies Tools
Python for Fun This collection is a presentation of several small Python programs. They are aimed at intermediate programmers; people who have studied Python and are fairly comfortable with basic recursion and object oriented techniques. Each program is very short, never more than a couple of pages and accompanied with a write-up. I have found Python to be an excellent language to express algorithms clearly. Some of the ideas here originated in other programs in other languages. From many years of programming these are some of my favorite programs. Many thanks to Paul Carduner and Jeff Elkner for their work on this page, especially for Paul's graphic of Psyltherin (apologies to Harry Potter) and to the Twisted developement team for their Lore documentation generator to which all the other web pages in this collection have been recently adapted. Chris Meyers
PyQT Tutorial Tutorial: Creating GUI Applications in Python with QTby Alex Fedosov Python is a great language with many awesome features, but its default GUI package (TkInter) is rather ugly. Besides, who wants to write all that GUI code by hand, anyway? So the following is a brief tutorial on how to go about creating your first semi-interesting application with Python & QT. First, you need to have the following packages installed: Python 2.x PyQt 3.x QT Designer 3.x I did everything with default packages that came with Fedora Core 1, and had no problems. QT Designer will come up. In the New/Open dialog box, click on Dialog, and hit OK. QT Designer will create a new dialog canvas for you and call it Form1. In the toolbar on the left select the LineEdit tool and create an edit box on the canvas. Now, select the ListBox tool in the toolbar on the left and create a list box on the canvas. Notice that there is already an item in the box. Double-click on the button on the canvas. Here's the tricky part.
Decorators I: Introduction to Python Decorators Computing ThoughtsDecorators I: Introduction to Python Decoratorsby Bruce EckelOctober 18, 2008 Summary This amazing feature appeared in the language almost apologetically and with concern that it might not be that useful. I predict that in time it will be seen as one of the more powerful features in the language. The problem is that all the introductions to decorators that I have seen have been rather confusing, so I will try to rectify that here. (This series of articles will be incorporated into the open-source book Python 3 Patterns & Idioms). First, you need to understand that the word "decorator" was used with some trepidation, because there was concern that it would be completely confused with the Decorator pattern from the Design Patterns book. Indeed, you can use Python decorators to implement the Decorator pattern, but that's an extremely limited use of it. The macro has a long history, but most people will probably have had experience with C preprocessor macros. The output is:
(the eff-bot guide to) The Standard Python Library Overviews (15) Core Modules [core-modules-index]Data Representation [data-representation-index]Data Storage [data-storage-index]File Formats [file-formats-index]Implementation Support Modules [implementation-support-modules-index]Internationalization [internationalization-index]Mail and News Message Processing [mail-and-news-message-processing-index]More Standard Modules [more-standard-modules-index]Multimedia Modules [multimedia-modules-index]Network Protocols [network-protocols-index]Other Modules [other-modules-index]Platform Specific Modules [platform-specific-modules-index]Preface [preface-index]Threads and Processes [threads-and-processes-index]Tools and Utilities [tools-and-utilities-index] Articles (249) The aifc module [aifc]The anydbm module [anydbm]The array module [array]The asynchat module [asynchat]The asyncore module [asyncore]The atexit module [atexit]The audiodev module [audiodev] The keyword module [keyword]The knee module [knee]
Python 201 -- (Slightly) Advanced Python Topics Dave Kuhlman Email: dkuhlman@rexx.com Release 1.00June 6, 2003 Copyright (c) 2003 Dave Kuhlman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Abstract: This document is a syllabus for a second course in Python programming. Contents This document is intended as notes for a course on (slightly) advanced Python topics. Defining a regular expression is to provide a sequence of characters, the pattern, that will match sequences of characters in a target. Comments:
Getting Started A First Application: "Hello, World" As is traditional, we are first going to write a Small "Hello, world" application. Here is the code: Toggle line numbers 1 2 import wx 3 4 app = wx.App(False) 5 frame = wx.Frame(None, wx.ID_ANY, "Hello World") 6 frame.Show(True) 7 app.MainLoop() Explanations: Note: You almost always want to use wx.ID_ANY or another standard ID (v2.8) provided by wxWidgets. Run the program and you should see a window like this one: Windows or Frames? When people talk about GUIs, they usually speak of windows, menus and icons. Building a simple text editor In this tutorial we are going to build a simple text editor. First steps The first step is to make a simple frame with an editable text box inside. 1 2 import wx 3 class MyFrame(wx.Frame): 4 """ We simply derive a new class of Frame. """ 5 def __init__(self, parent, title): 6 wx.Frame. In this example, we derive from wx.Frame and overwrite its __init__ method. Every application should have a menu bar and a status bar. Dialogs
WebKit in PyQt - rendering web pages In the 4.4 release of Qt bindings to WebKit have been added. WebKit is a web page rendering engine, that is used in Safari and Google Chrome. Qt bindings are also available in PyQt and in other languages. To get qt-webkit we need just Qt and PyQt 4.4 or newer. Linux users have to check if they have "qt-webkit" installed (if qt comes in several packages). Here is a basic QWebView usage: #! Sample result: Functionality of the "browser" is currently low, but WebKit bindings provide a lot of goodies. Now we will make more functional example browser. Now we make a Python class from that UI: pyuic4 httpWidget.ui > httpWidget.py And we can code the rest: Connect signals with slots QWebView signals (like page loading status, page title)Buttons signalsUI look configuration Here is the final code for the UI we designed: Save the code in a file in the same directory as the UI file, and run it (i used run.py): python run.py In the __init__ we set the default web page, and some margins for the widgets.