15,181 Topics

Member Avatar for
Member Avatar for vegaseat

The surface or canvas established with wx.PaintDC() can be used to draw a number of shapes like lines, rectangles and circles. The snippet shows you how to select colors and then draw a few simple shapes. Use help(wx.PaintDC) to get information about the many things you can use this surface …

1
865
Member Avatar for mawe

The name says it all, I think. You have a nested list, you want to flatten it (e.g. because you want to count the occurence of an element), this function is all you need ;)

1
819
Member Avatar for Ene Uran

The small images you put on buttons and such are nice, but a real pain if you have to attach all those image files to your program. Python's base64 encoding module makes it easy to convert the binary image code to a string that you can simply make part of …

Member Avatar for vegaseat
0
2K
Member Avatar for Matt Tacular

Ever have two lists in python and you want to know what how much of one list the other contains? This code snippet will help you do that.

Member Avatar for vegaseat
0
351
Member Avatar for vegaseat

This little program uses Python and it's module pygame to do some sprite type animation. The rectangle that contains the image is moved and bounced within the window's frame. Pretty crude, since the whole screen frame is erased for each move. Actually it works smooth enough, and is relatively flicker …

Member Avatar for vegaseat
1
950
Member Avatar for vegaseat

Sometime in my childhood biology class I heard that the fancy colors of butterfly wings aren't really true colors, but interference patterns. This program claims to create interference patterns using a series of 3d sine waves using Python's popular pygame module. The whole contrivance is pretty to look at, and …

0
218
Member Avatar for Ene Uran

Nothing fancy. just shows a simple monthly calendar in a Tkinter label. The trick is to use a fixed font so spaces take up the same area as numbers.

Member Avatar for ndhdo
0
285
Member Avatar for vegaseat

The assumption is, that the typical workweek starts with Monday and ends with Friday. This is something the average working bloke has to live with (unless you work for a bank or the government). This little code will spit out a listing of all the workdays of a given month. …

1
3K
Member Avatar for jrcagle

Inspired by Bumsfeld's color tester, and wanting to give my students some practice at interpreting color strings, I wrote a little Tkinter program that asks the user to chose one of six buttons whose color most closely matches the color string printed at top. Comments welcome, and does anyone know …

0
217
Member Avatar for vegaseat

Yes, the Python module 'zipfile' can handle an archive of files. This snippet shows you how to pack a PKZIP format zip file with several files and then unpack these archived files to individual files again.

Member Avatar for 1337455 10534
0
685
Member Avatar for jrcagle

So I needed a way to represent a line in Python. My first stab was to create a function dynamically. But classes are so much ... classier, so here's a simple implementation of a line object, with plenty of room for additional methods. The line is created as l = …

Member Avatar for jrcagle
0
2K
Member Avatar for vegaseat

For those of you who think that an interpreted language like Python has to be slow, here is a small surpise. This snippet will draw a fair sized Mandelbrot set in a relatively short time. I cheated just a little, drawing the set in only black and white. Hey, nothing …

1
857
Member Avatar for vegaseat

Here is an example of a random spin button using a button surrounded by labels to create the feeling of a spin animation. This example uses the Tkinter GUI and lets you select numbers 1 to 6. If your game requires more then this, just add additional labels. You are …

Member Avatar for Bill Fisher
0
599
Member Avatar for bumsfeld

The FlashWindow component of wxPython will play those nice animated flash files found on the internet. They have file extension .swf usually.

Member Avatar for akennedy93612
0
418
Member Avatar for Ene Uran

Let's say you had a list of full names, where the name would consist of a title, followed by first, middle and last name, or maybe just title and last name. You can sort this list by last name only, by creating a temporary list of sublists of type [last …

0
480
Member Avatar for IP2Location

This module is a Python Library to support all IP2Locationâ„¢ database products. It has been optimized for speed and memory utilization. Developers can use the API to qeury all IP2Locationâ„¢ binary databases for applications written in Python.

0
628
Member Avatar for vegaseat

This little snippet combines a Tkinter GUI application with sound from the pygame mixer. The snippet should do fairly well across platforms. I tested it on a Windows XP machine, but let me know your experience with other platforms.

0
449
Member Avatar for Mouche

This game takes a random word from a list, gives you five prompts to guess letters in the word, and then it shows you a "masked word," filling in the letters you've guessed. Say the word is "hockey" and the user guesses: 'h,' 'e,' 't,' 'r,' and 's.'The masked word …

0
274
Member Avatar for vegaseat

This shows you how to draw a colorful bar graph of a data set using the Tkinter canvas and rectangles. An attempt has been made to use most of the canvas area for the graph. The bars are spaced and labeled with the corresponding value. The x-axis is simply the …

2
4K
Member Avatar for Ene Uran

The snippet shows the use of a list of class instances to form a sortable and searchable database for solvents, or for that matter other chemicals. The list can be expanded and all the needed data added at the same time.

0
267
Member Avatar for vegaseat

You can use the Tkinter canvas and the canvas.create_line() function to draw a line plot of a mathematical function. The canvas.create_line() function accepts a list of x, y points that you can create within a for loop. The resulting plot is centered and can be stretched along the x and …

0
2K
Member Avatar for bumsfeld

The wxPython GUI tool makes it very simple to create nice looking analog clock. The analog clock component was put into simple dialog frame and can be moved about the screen.

0
722
Member Avatar for vegaseat

Another famous fractal called the Sierpinski Triangle named after Polish mathematician Waclaw Sierpinski. He seemed to have played around with it the most. To state it simple, you start with an equilateral triangle and then form smaller triangles by connecting the midpoints of each of the sides. Some folks shade …

1
1K
Member Avatar for Ene Uran

A list of tuples is easy to sort for items in the tuples. This snippet shows you how to sort a (character, frequency) tuple either by character or by frequency. One useful example would be the sorting and display of a list of (player, score) tuples, you might find in …

0
244
Member Avatar for vegaseat

This is a short code example using the function os.stat() to get some of the basic file information. Things like file size, times the file was created (Windows), last modified, and last accessed. The program uses a dictionary in an interesting way to store and display the information. The times …

0
2K
Member Avatar for vegaseat

There are situations in Python code when a function is used as an object rather then a function call. Handling arguments becomes a mild problem, that can easily be handled by wrapping the function object and its arguments. One common way is the use of a curry function or class. …

1
194
Member Avatar for vegaseat
Member Avatar for RonaldDuncan
0
2K
Member Avatar for vegaseat

Some computer languages have a goto statement to break out of deeply nested loops. Python has chosen not to implement the much abused goto. There are other, really more elegant, ways to accomplish the same outcome. Here are three examples.

Member Avatar for jrcagle
1
3K
Member Avatar for bumsfeld

Here we search a Python script file (or other text file) for one certain string, and copy any files containing this string to another folder.

0
209
Member Avatar for bumsfeld

Search for a file given its name and the starting search directory. The search is limited to a set depth of subdirectories. Python makes this easy to do.

0
209

The End.