This code shows how to obtain and display a GIF image from an internet website using the Tkinter GUI toolkit that comes with the Python installation.

Member Avatar
Member Avatar
+4 forum 7

Let's say you want to send a short private message to your friend, but don't want grandma to snoop around and find it. One way is to use the Python Image Library (PIL) and hide the message in a picture file's pixels. Just looking at the picture you will barely detect any difference between the before and after picture. All your friend needs is the decode_image portion of this simple code to get the message back.

Member Avatar
Member Avatar
+5 forum 11

This short Python code gets the local time from the PC as a formatted string using time.strftime('%H:%M:%S'). The time string is displayed in a label using a larger font. A recursive function checks the time five times per second, and updates the time string, if it has changed. Five times per second may sound like overkill, but keeps the display from acting spasmodic.

Member Avatar
Member Avatar
+2 forum 12

Shows how to create a basic slide show with the Python Tkinter GUI toolkit.

Member Avatar
Member Avatar
+4 forum 19

This simple isprime(number) function checks if the given integer number is a prime number and returns True or False. The function makes sure that the number is a positive integer, and that 1 is not considered a prime number. To find out if an integer n is odd one can use `n & 1`, to check for even one can then use `not n & 1` or the more traditional `n % 2 == 0` which is about 30% slower.

Member Avatar
Member Avatar
+2 forum 35

This class gives a specified Tkinter widget a tooltip that appears as the mouse is above the widget. You can improve the code by putting in a time delay.

Member Avatar
Member Avatar
+7 forum 4

This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets.

Member Avatar
Member Avatar
+0 forum 4

PySide (public license PyQT) is my preferred Python GUI toolkit. Here we explore how to test some of the widgets available and create a digital clock.

Member Avatar
Member Avatar
+3 forum 2

This code creates a sound file in Sun's simple AU audio format of a sine wave of given frequency, duration and volume.

Member Avatar
Member Avatar
+1 forum 4

Sometimes when you get a large check from your employer, the value is written out in words. I get those all the time of course. So I wrote this little Python code to convert an integer value to english words. Numbers as high as 999 vigintillion can be used. In case you don't know, a vigintillion is 10 to the power 60. That is what our national deficit will be soon.

Member Avatar
Member Avatar
+3 forum 4

Another application of Python module base64, this time to embed midi music data in your program. You also need the module pygame to execute this Python code. Enjoy the music!

Member Avatar
Member Avatar
+5 forum 9

You can put an image and text on a Tkinter button widget. This small code shows you how. The GIF image file you want to use for the button should be in the working directory, or you have to give it the full path. Incorporate the Python Image Library (PIL) for other image formats.

Member Avatar
Member Avatar
+1 forum 3

Just a relatively simple calculator using the Tkinter GUI. It has a few nice features such as correcting division by an integer (for older Python versions), error trapping, to and from memory buttons, and an editable display. The editable display allows you to backspace mistakes, and also to enter things not on the key pad, like hexnumbers. For instance if you enter 0xFF and press equals, it will give you the decimal (denary) equivalent of 255 The program also has a guard against the bad guys that like to abuse the underlying eval() function to wipe out files. I wrote …

Member Avatar
Member Avatar
+5 forum 14

This snippet defines a function restart_program() which restarts your python program from within your python program.

Member Avatar
Member Avatar
+4 forum 27

**Usage:** Provides a secure frontend object with restricted access to attributes of the backend object.

Member Avatar
Member Avatar
+0 forum 1

A little fun with Python's turtle module drawing a number of random stars in the dark sky.

Member Avatar
Member Avatar
+2 forum 3

A short example of Pygame showing an image with a known internet url.

Member Avatar
Member Avatar
+0 forum 1

Use Python module threading to count intervals (in seconds) in the background. You can use this to time any relatively slow event like the time it took to finish a game or play some music. You can also peek at the current interval value as the event goes on. Go ahead and explore. Just an example how to run time.sleep() in a thread.

Member Avatar
Member Avatar
+0 forum 6

A list of class objects mimics a C array of structures. The snippet explores how to setup the list, and sort the list according to a selected attribute. Then we use a format string to display the sorted list. Take a look at how to search the list. All in all an easy way to handle structured data.

Member Avatar
Member Avatar
+2 forum 5

This snippets contains a python program to find a shortest solution to the problem of the farmer who whishes to cross a river. The boat can only contain two things, including the rower. The farmer comes with a wolf, a duck and a bag of corn, and he can't leave the duck alone with one of the other items because the wolf would eat the duck, or the duck would eat the corn. The program shows how to use a `collections.OrderedDict` to implement a stack without repetitions. This is used to traverse a tree of states. These states, encoded as …

Member Avatar
Member Avatar
+0 forum 5

Using PySide's QAbstractTableModel allows you to easily customize a widget like QTableView and make it more generic in its application. Here we use it to present solvent data in tabular form and sort each column content by simply clicking on the header. You can feed it any data as long as you stick to the format of the data used, a header list and a list of data tuples/lists.

Member Avatar
Member Avatar
+4 forum 7

The Tkinter module comes with the normal Python installation. It allows you to create Python GUI programs for Windows, Linux or Unix on the Mac. In this snippet we put a GIF image (.gif) onto a form's canvas with just a few lines of code. Most of the lines are remarks to explain what is going on.

Member Avatar
Member Avatar
+0 forum 6

Using the wx.lib.pdfwin.PDFWindow one can read Adobe PDF files (.pdf) with wxPython. The PDF file format is popular document file format allowing mixing of text and graphics. The GUI toolkit wxPython's newer wx.activex module allows one to use the ActiveX control, as if it would be one wx.Window. It actually embeds the Adobe Acrobat Reader into the wx.Window.

Member Avatar
Member Avatar
+0 forum 9

The Tkinter GUI toolkit comes with a scrolled text widget that is called ScrolledText. To get access to it you have to import it separately. It allows you to display large amounts of text in a small space.

Member Avatar
Member Avatar
+0 forum 2

If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help.

Member Avatar
Member Avatar
+1 forum 10

Sometimes we want to not split by every space character, but we want to split only on those outside of brackets and quotes. This way we can have for example quoted string as single argument for command. EDIT: 1. Added hierarchical nesting of same kind of brackets. 2. Bunching multiple separators as single separator, None as general whitespace separator Test output: ---------------------------------------------------------------------------------------------------------------------------------- Hello, (Tony 'pyTony' Jarkko Veijalainen) {'This 'is' quoted' Great to "split" this} split "Also Quoted part" [test test] end Hello, (Tony 'pyTony' Jarkko Veijalainen) {'This 'is' quoted' Great to "split" this} split "Also Quoted part" [test test] end …

Member Avatar
Member Avatar
+1 forum 2

This simple key logger shows any character/special key when pressed.

Member Avatar
Member Avatar
+3 forum 3

This snippet defines a function returning new identifiers created from reading the computer's time.

Member Avatar
Member Avatar
+0 forum 5

The module pyglet leans on OpenGL for graphics and is used in the scientific community together with Python. This short code snippet shows you how to use it to display an animated GIF file. The download is free, so give it a try. You don't have to download OpenGL to use pyglet.

Member Avatar
Member Avatar
+4 forum 3

Just a simple exploration of the goslate module (uses the Google Translate API) to translate some common languages. However, some IDE's create character problems. Note: Your computer has to be connected to the Internet to access Google.

Member Avatar
Member Avatar
+3 forum 3

The End.