4,305 Posted Topics

Member Avatar for Lardmeister

Lardmeister, very nice advice. I still had VC# 2003 on one of my old machines. You are right, it makes great GUI templates. I will be converting my Python mortgage calculator programs from a boring Python console program to a nice C# GUI program and post it in the C# …

Member Avatar for vegaseat
0
456
Member Avatar for Lardmeister

Lardmeister, nice of you to point out the C# programs don't necessarily need Visual C# to run. I can run your code from my ConText general programming IDE, just have to tell it where csc.exe is located. Good info to have! I can also run it from the SharpDevelop IDE, …

Member Avatar for Lardmeister
0
159
Member Avatar for Lardmeister

A real nice example of a C# GUI program. Thanks for the comment on running it simply from the c# compiler csc.exe that seems to come with most Windows installations.

Member Avatar for vegaseat
0
175
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
870
Member Avatar for Ene Uran

[COLOR=#0000ff]Ene, just a note ...[/COLOR] [COLOR=#0000ff]base64.encodestring(open(gif_file).read()) [/COLOR] [COLOR=#0000ff]should be ...[/COLOR] [COLOR=#0000ff]base64.encodestring(open(gif_file,"rb").read())[/COLOR] [COLOR=#0000ff]that's why you have problems with a fair number of image files. [/COLOR]

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

Since your function returns list_percentage, call your function this way: list_percentage = listPercentage(li2,li1) print list_percentage You don't need the 'ugly global' in the function. Interesting code otherwise! Also, the code as is 'spits out' 50% not 25% If you change li2 to [1,2,3,4,4,4,4,9] things get goofy!

Member Avatar for vegaseat
0
360
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
967
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
222
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 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
688
Member Avatar for jrcagle
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
864
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
606
Member Avatar for bumsfeld
Member Avatar for akennedy93612
0
422
Member Avatar for gabriel_wadley

Glad to see someone is interested in music! You can simplify your code a little by calculating the frequency for a given musical note. See this snippet: [url]http://www.daniweb.com/code/snippet359.html[/url] It is written in Python and should be very easy to understand.

Member Avatar for vegaseat
0
6K
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
453
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 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 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 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
207
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 vegaseat

Yet Another Calculator using wxPython, smaller, but more advanced than the previous one. Wrote this one to test the Curry class, but it didn't work well. So there is no curry there. I found out that one has to be careful with the eval() function. If you write 012 instead …

1
155
Member Avatar for vegaseat

Let mathematics do your art work! It is amazing how a simple mathematical formula can draw very intricate shapes. Here we draw a fractal tree on a Python Image Library (PIL) blank image, and save the finished drawing as an image file in one of the popular formats. Look at …

0
693
Member Avatar for vegaseat

The wx.BitmapButton shows an image, great for those folks who think that a picture is worth a thousand words. The snippet gives an example how to load the image, size the button, and put the image on the the button.

Member Avatar for InfoClock
0
826
Member Avatar for vegaseat

Just a small Python program to calculate monthly payments and other costs. I have compared it with some of the calculators available from many of the online mortgage companies, and results seem to match.

2
1K
Member Avatar for vegaseat

In this snippet we are playing around with wxPython's buttons, showing you how to bind the mouse click event, enable and disable, show and hide the buttons. Each button also has a tool-tip (hint) associated with itself.

Member Avatar for Racoon200
0
4K
Member Avatar for vegaseat

If you want a variable in a C function to retain its last assigned value, you simply declare it as static. Python does not have static variables, but you can impersonate one in different ways. The default list argument is my preferred option. Here are some examples.

0
601
Member Avatar for vegaseat

Py2Exe takes your Python code file and packages it into an executable file that you can distribute to a client that does not have Python installed. The executable file contains your byte code, all the required modules and the Python interpreter. It is not a small file. The snippet is …

Member Avatar for Aestter
1
375
Member Avatar for vegaseat

This small snippet shows how to load and display HTML (Hyper Text Markup Language) with wxPython's HtmlWindow(). This could be particularly useful with instruction and help text. HTML allows you to include pictures, fancy fonts and links.

0
1K
Member Avatar for vegaseat

When I first met folks in Las Vegas that used biorhythm values of the top players in a team to place their bet, I thought they were a little odd. Some of them were successful, but I am sure biorhythms were not the only thing they considered. You can read …

0
3K
Member Avatar for vegaseat

Just in time, a short Python code snippet to calculate the date of Easter Sunday of a given year. This can be expanded to calculate the important date of Mardi Gras too.

0
4K
Member Avatar for vegaseat

Using an SDL (Simple DirectMedia Layer) wrapper is one way to play sound and music with Ruby. I have tested this snippet with .MID .MOD and .WAV files and it performs well. There are several SDL wrappers for Ruby available, I picked RUDL because of its simplicity. RUDL is great …

0
295
Member Avatar for vegaseat

I took the data of an old State Trivia game and applied it to Python. The data forms a series of lists with matching indexes. One example of how to ask a trivia question, present four possible answers, and how to evaluate the correct answer is given. You can expand …

0
744
Member Avatar for vegaseat

A list comprehension derives a new list from an existing list, and was adopted by Python from the Haskell language. This snippet tries to explain the development of list comprehension and shows a number of uses, including nested list comprehension. The benefits are simplicity (after an initial learning bump) and …

1
253
Member Avatar for vegaseat

The lowly soundcard in your PC has fascinating capabilities. All you need is a module that can handle the Musical Instrument Digital Interface (MIDI). Tell the soundcard which instrument to play, specify the musical note, the duration, the beat and other things. The sound chip makes 127 instruments available and …

Member Avatar for caribedude
1
680
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
445
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
835
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
413
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 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
884
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
169
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
571
Member Avatar for vegaseat

This code shows you how to build a multiline story string that should display similarly to way it shows in the code. It should be relatively easy to maintain.

Member Avatar for bumsfeld
2
115
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

The End.