The Curses Module
(Unix only, Optional). The curses module gives you better control of the text terminal window, in a terminal-independent way.
(Unix only, Optional). The curses module gives you better control of the text terminal window, in a terminal-independent way.
(Obsolete). This (highly incomplete) module contains a parser for timezone specifications. When you import this module, it parses the content of the TZ environment variable. Example: Using the tzparse module # File: import os if not os.environ.has_key(“TZ”): # set it to something… os.environ[“TZ”] = “EST+5EDT;100/2,300/2” # importing this module will parse the TZ variable import
The tzparse module Read More »
(New in 2.0). This module reads robots.txt files, which are used to implement the Robot Parsing. If you’re implementing an HTTP robot that will visit arbitrary sites on the net (not just your own sites), it’s a good idea to use this module to check that you really are $ python robotparser-example-1.py may fetch the home page
The robotparser module Read More »
The TidyHTMLTreeBuilder parser can read (almost) arbitrary HTML files, and turn them into well-formed element trees. This parser uses a library version of Dave Raggett’s HTML Tidy utility to fix any problems with the HTML before converting it to XHTML (the XML version of HTML). Note: If you don’t want to (or cannot) install binary Python extensions, you can use the TidyTools module
ElementTree Tidy HTML Tree Builder Read More »
The ElementSoup module is a (slightly experimental) wrapper for Leonard Richardson’s robust BeautifulSoup HTML parser, which turns the BeautifulSoup data structure into an element tree. The resulting combo is similar to ElementTidy, but a lot less picky. And therefore, a lot more practical. Which is good. Code (latest versions): Just grab the files and put them in your project directory,
The ElementSoup Module Read More »
To update the text displayed on a button in Tkinter, you can use the config() method or the configure() method to modify the button’s text attribute. Here’s an example: import tkinter as tk def update_text(): button.config(text=”New Text”) # Update the button text root = tk.Tk() button = tk.Button(root, text=”Old Text”) button.pack() update_button = tk.Button(root, text=”Update
How do you update the button text in Tkinter? Read More »
The xmllib module This module provides a simple XML parser, using regular expressions to pull the XML data apart. The parser does basic checks on the document, such as checking that there is only one top-level element, and checking that all tags are balanced. You feed XML data to this parser piece by piece (as
You’ve been working on a complex Python script, investing hours of effort and dedication to ensure its smooth execution. You’ve accounted for every possible scenario and exception, meticulously crafting your code. However, there’s one often-overlooked aspect: the graceful exit. When your script completes its task or encounters an unexpected error, how can you ensure that
atexit module in python Read More »
This module implements a simple helper class, HTTPClient, which can send an XML document (represented either as an element tree or a string) to a remote server, and parse the result into an element tree. A Simple XML-Over-HTTP Helper (File: HTTPClient.py) The main workhorse is the do_request method, which uses the httplib library module for all protocol-related stuff. The HTTP class represents a connection to
xmlhttp: A Simple XML-Over-HTTP Class Read More »
The Label widget is a standard Tkinter widget used to display a text or image on the screen. The label can only display text in a single font, but the text may span more than one line. In addition, one of the characters can be underlined, for example to mark a keyboard shortcut. When to use the
The Tkinter Label Widget Read More »
(New in 2.2) Tools for manipulation of all sorts of email messages. The email package replaces simpler modules, such as rfc822 and mimetools, with a much more flexible message object, and associated parsers. Parsing Messages The easiest way to parse messages is to use the message_from_file or message_from_string helpers in the email toplevel module. The former takes a file handle, the latter a string object: Parsing
I just added support for a new “pixel access” method to PIL 1.1.6. The load method now returns a pixel access object, which behaves like a 2-dimensional mapping. You can use the access object on both sides of an assignment statement; as an expression, it fetches the given pixel value, and as an assignment target, it updates
Pixel Access Objects Read More »
The Tkinter BitmapImage Class The BitmapImage class provides a simple image class, for monochrome (two-color) images. When to use the BitmapImage Class This class can be used to display bitmap images in labels, buttons, canvases, and text widgets. The bitmap loader reads X11 bitmap files. To use other formats, use the PhotoImage class. Patterns An X11 bitmap image consists of
The Tkinter BitmapImage Class Read More »
A Python Code Generator A common complaint about Python’s syntax is that it’s impossible to generate Python code on the fly, from a program. Here’s a simple helper class that helps you do exactly that: # # a Python code generator backend # # fredrik lundh, march 1998 # # fredrik@pythonware.com # http://www.pythonware.com # import sys,
A Python Code Generator Read More »
The ImageGrab Module The ImageGrab module can be used to copy the contents of the screen or the clipboard to a PIL image memory. The current version works on Windows only. Functions grab ImageGrab.grab() ⇒ image ImageGrab.grab(bbox) ⇒ image (New in 1.1.3) Take a snapshot of the screen, and return an “RGB” image. The bounding box argument can be used
The ImageGrab Module Read More »
Element Library Functions March 22, 2004 | Fredrik Lundh ElementTree 1.3 may include a new module, ElementLib, with a number of convenient helper functions. The exact contents are yet to be determined; here are some of the current proposals (from various sources, in no specific order): Helpers to add subelements, with a nicer syntax. Wrappers to access
Element Library Functions Read More »
ElementTree provides limited support for XPath expressions. The goal is to support a small subset of the abbreviated syntax; a full XPath engine is outside the scope of the core library. The 1.2 release supports simple element location paths. In its simplest form, a location path is one or more tag names, separated by slashes (/).
XPath in ElementTree Read More »
The ImageEnhance module contains a number of classes that can be used for image enhancement. Example Vary the Sharpness of an Image import ImageEnhance enhancer = ImageEnhance.Sharpness(image) for i in range(8): factor = i / 4.0 enhancer.enhance(factor).show(“Sharpness %f” % factor) Also see the enhancer.py demo program in the Scripts directory. Interface All enhancement classes implement a common interface, containing a single
The ImageEnhance Module in PIL Read More »
Using the Image Class The most important class in the Python Imaging Library is the Image class, defined in the module with the same name. You can create instances of this class in several ways; either by loading images from files, processing other images, or creating images from scratch. To load an image from a file, use
Image Class in Python Image Library (PIL) Read More »
The Radiobutton is a standard Tkinter widget used to implement one-of-many selections. Radiobuttons can contain text or images, and you can associate a Python function or method with each button. When the button is pressed, Tkinter automatically calls that function or method. The button can only display text in a single font, but the text may span more than
The Tkinter Radio Button Widget Read More »
The Simple Object Access Protocol (SOAP) is an XML-based protocol for “information exchange in distributed environments”. SOAP can be used in many different ways, but the most common approach is to use it for RPC requests over HTTP, where a client application sends a SOAP request message to a remote server, and the server returns a SOAP
Using the ElementTree Module to Generate SOAP Messages Read More »
The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities. The current stable version is 1.1.7, released in November 2009. The next release will be 1.2, with “early 2011” as the release target. Prebuilt versions of PIL are available in most Linux
Python Imaging Library Read More »
The Python Imaging Library handles raster images; that is, rectangles of pixel data. Bands An image can consist of one or more bands of data. The Python Imaging Library allows you to store several bands in a single image, provided they all have the same dimensions and depth. To get the number and names of bands
Python ImagingBook Concepts Read More »
In this post, we will see how to create a simple Animation inside a canvas in Tkinter module in Python. The above code will give you the result as shown below:
A Simple Animation Engine in Tkinter Read More »
Tkinter is a standard library in Python that is used to create Graphical User Interface (GUI) based desktop applications. It is pronounced (Tk inter). You can learn more about Tkinter in the tkinter tutorial. How to create pop-up menus in tkinter?
Tkinter Popup Menus Read More »
When to use the Spinbox Widget The Spinbox widget can be used instead of an ordinary Entry, in cases where the user only has a limited number of ordered values to choose from. Note that the spinbox widget is only available in Python 2.3 and later when linked against Tk 8.4 or later. Also, note that several
The Tkinter Spinbox Widget Read More »
The consumer interface is a simple “data sink” interface, used by standard Python modules such as xmllib and sgmllib. Other examples include the GZIP consumer and PIL’s ImageParser class. The consumer will typically convert incoming raw data in some way, and pass it on to a another layer. For example, XML parsers implementing this protocol usually parse the data stream into a stream of
The Consumer Interface in Python Read More »
This article discusses how to synchronize access to shared resources and otherwise coordinate execution of threads. Synchronizing Access to Shared Resources One important issue when using threads is to avoid conflicts when more than one thread needs to access a single variable or other resource. If you’re not careful, overlapping accesses or modifications from multiple
Thread Synchronization Mechanisms in Python Read More »