background preloader

GUI Programming with PyQT

GUI Programming with PyQT

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

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

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:

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.

The Django Book Frame, Text, Scrollbar, Scale < Widgets 2 < Perl/Tk Tutorial < Perl Frame A frame is a simple widget. Its primary purpose is to act as a spacer or container for complex window layouts. Some OptionsExample #! Text A text widget displays one or more lines of text and allows that text to be edited. Some Options Example #! Scrollbar A scroll bar is a widget that displays two arrows, one at each end of the scroll bar, and a slider in the middle portion of the scroll bar. #! grid As you can see I have used 'grid' here. Using grid requires a bit of experience - but if you know HTML it would help a lot. Scale Makes a slider that can be adjusted by the user to input a variable. #! Now our little example is becoming more and more like a program.

The Art of Programming Programming and art can no longer be thought of as totally different worlds. They join each other as one in computer games, mobile apps, and software. 3D graphic arts and animated graphics give life to each game you play and each application you use. Computer graphic arts and modern programming are now interlaced as logic just is one with the creativity of geniuses. Einstein often mentioned that when he hit a logical stumbling block, he grabbed his violin and stimulated his creative juices to solve the problem. Toonzcat.com is your entry portal into other dimensions that will help develop skills and expand your knowledge of animated graphic arts and programming. Start Here: Python 3x Programming for Beginners This is a short, free, e-book, to download and begin your journey into Python 3x programming. Intro To Game Making A short article to introduce game making and game development for the beginnner.

Related: