15,190 Topics

Member Avatar for
Member Avatar for vegaseat

Boo is new, well at least relatively new. If you are familiar with Python and C#, you can feel right at home. Most of Boo is written in C# by a Python devotee. Boo has static typing, but also mimics dynamic typing by inference. This way you are not in …

Member Avatar for vegaseat
3
443
Member Avatar for vegaseat

The wx.ComboBox is a combination of an editbox and a (dropdown) listbox. It let's the user slect an item from the listbox and puts it in the editbox. In this snippet we use two comboboxes, each used to select an area unit of measurement. Once selected, an area value can …

1
2K
Member Avatar for vegaseat

Not much excitement in that standard wxPython empty window icon. It's time you put a more picturesque icon up there. This snippet shows you how to use an embedded icon or your own icon you have as an icon file in your working folder. Actually, the embedded icon is written …

0
1K
Member Avatar for vegaseat

In this experiment we call the paint event and establish a device context to draw a rectangle and fill it with the color set by the brush. Actually, we will draw 99 random sized and random colored rectangles with a small time delay. Don't worry, it will be faster than …

0
828
Member Avatar for vegaseat

The wxPython widget wx.Gauge is commonly called a progress bar. In this code snippet I have bound the wx.Gauge to a wx.Slider, as you move the slider so do the indicating bars of the gauge. A second method is explored too, here the gauge indicates the progress of a timed …

0
400
Member Avatar for vegaseat

Using a wxPython GUI program to find the position of the mouse when clicked within the frame/window. Also sets the color of the frame and changes the cursor to a pencil. The title bar of the frame displays the coordinates of the mouse position.

1
2K
Member Avatar for G-Do

Suppose you are a medical researcher studying diabetes. Your boss has given you a big chart of data from diabetes patients. Each row of the chart has information for one patient. Each column of the chart is a health-related statistic, such as height, weight, age, blood pressure, cholesterol level, etc. …

2
1K
Member Avatar for vegaseat

Create a dictionary with char:count pairs, change the dictionary to a list of (char, count) tuples, sort the list by character and display the result. That's all there is to counting and displaying the characters in a given string. Just a few lines of Python code.

0
877
Member Avatar for vegaseat

This short code lets you create a base64 encoded image string, that you can copy and paste into your Python program code to display relatively small embedded images. For a typical application see: [url]http://www.daniweb.com/code/snippet393.html[/url]

1
1K
Member Avatar for vegaseat

Small image files can be embedded in Python code using the base64 encoded string of the image. If you have to present a number of small fixed images in your program, embedding might be easier than including a set of image files. Attached files can be lost, and than your …

2
4K
Member Avatar for vegaseat

Here is a generator function using find() to do a search for all the occurances of a substring in a text. It will give you all the positions/indexes within the text where the substring is located. The sample text here can be replaced by text read in from a file.

0
166
Member Avatar for vegaseat

This snippet takes a look at Python file handling. Different ways to write and read text files, zipped files and memory streams. Investigates how to access only part of a file. Also explores the "read" of a binary image file and performs a hex-dump of the data.

0
567
Member Avatar for vegaseat

For loops in Python are quite versatile. The little keyword "in" allows you to loop through the elements of all kinds of sequences, may the elements be numbers, characters, strings, objects like tuples and more. Here is an example comparing range(), xrange() and a generator similar to xrange().

Member Avatar for vegaseat
0
2K
Member Avatar for vegaseat

Years ago I wrote a little screen-saver in Delphi that randomly put colorful circles all over the screen. A hit with the secretaries in the office. I modified a simple Tkinter based snippet to put the same colorful circles all over a window form at random locations, random radii and …

0
1K
Member Avatar for vegaseat

VPython's fame is with 3D animated modeling, but it's plotting abilities, while not flashy, are easy to understand and very useful. This program uses VPython to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x).

2
302
Member Avatar for G-Do

Here's a cute little encipher/decipher program with a Tkinter GUI I wrote a while back. It's an implementation of a derivative of the Vigenere algorithm; the algorithm is taken from Laurence Smith's Cryptography: The Science of Secret Writing, Amazon link here. It's a dated book (and the technique itself is …

0
242
Member Avatar for vegaseat

Python has a module specifically made for timing built-in or owner coded functions. This code snippet explains how to use this feature.

1
242
Member Avatar for vegaseat

The psyco module has been around for a while and has been used to speed up the Python interpreter. For those of you who think speed is all important, take a look at a typical example. Psyco is similar to Java's just in time compiler. How does psyco do it? …

0
224
Member Avatar for vegaseat

Python24 introduces the function decorator that lends itself nicely to the timing of a function. As a sample function we are using the ever popular and rather stodgy prime number generator. The prime number generator seems to exist only to fluster students and to make niggling comparisons of the speed …

Member Avatar for vegaseat
1
2K
Member Avatar for bumsfeld

Just a colorful ten second countdown to New Year. Hope you can learn some code from it.

0
3K
Member Avatar for vegaseat

The Python module zlib allows you to compress a typical text string to about one half its original size. A handy feature when you have to transmit or save a large amount of text or data. It saves you time both writing and later reading back the compressed file. The …

0
1K
Member Avatar for vegaseat

Python uses C syntax to perform bitwise operations. Take a look at code that introduces you to bitwise operations at the binary level.

1
299
Member Avatar for vegaseat

If you have a Windows computer you can play musical beeps through the internal speaker. In this case it will sound like a very tiny Big Ben, brought to you by the module winsound and its method Beep().

2
2K
Member Avatar for vegaseat

Did you ever want to know how how many square inches are in a square meter? This short Python code allows you to get the answer. It uses a dictionary to simplify the conversions. Could be the start of a nice GUI program using radio buttons.

Member Avatar for vegaseat
2
3K
Member Avatar for vegaseat

The Python list container can be used for many practical things. In this somewhat light-hearted introspection of modern day politics we are looking at two lists and attempt to clear out elements that shouldn't be in both lists. No offense to anyone is intended, the outcome with the sets was …

Member Avatar for vegaseat
2
224
Member Avatar for vegaseat

A while ago I created a code snippet in C for the same question. Solving this question with Python is a lot simpler, and on top of that Python takes care of impossible dates with the appropriate error message.

Member Avatar for Lingson
2
224
Member Avatar for yuppie
Member Avatar for vegaseat

Jumping through a few extra hoops allows you to display the common image format jpeg on a panel of the wxPython GUI window. All you need to do is to read in the image file as a binary, convert to a byte stream image and then to a bitmap. Now …

Member Avatar for Erik Vandamme
0
3K
Member Avatar for vegaseat

The other day I was looking at my family tree. There are my parents Antonio and Lucy Vegaseat, then my grandparents Alfonso and Ludmilla Vegaseat on my father's side and Roland and Helga Gruenspan on my mother's side. Then come my great grandparents, by now there are eight of those. …

Member Avatar for vegaseat
0
195
Member Avatar for vegaseat

While the calculation of the total resistance of two resistors in parallel is simple, this code shows you how to trap a number of potential errors that come with the entry of the required data. All is wrapped easily into a colorful GUI program, due to the simplicity of the …

2
3K

The End.