4,305 Posted Topics
Re: 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# … | |
Re: 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, … | |
Re: 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. | |
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 … | |
Re: [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] | |
Re: 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! | |
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 … | |
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 … | |
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. … | |
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. | |
Re: Very nice Jeff! You may want to add a few lines of testing the class. | |
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 … | |
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 … | |
Re: Also works with earlier versions like Python24 and wxPython26. | |
Re: 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. | |
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. | |
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 … | |
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 … | |
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 … | |
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 … | |
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. … | |
This Python code shows a way to retrieve a picture from a web page and save it to a file. | |
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. | |
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 … | |
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 … | |
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. | |
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. | |
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. | |
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. | |
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 … | |
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. | |
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 … | |
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. | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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. | |
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. | |
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] | |
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 … | |
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. | |
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. | |
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. | |
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(). |
The End.