15,181 Topics
| |
This Python code will search for given filename starting with given directory. It will also search all the subdirectories in the given directory. The search will end at the first hit. | |
Code snippet to show you how to verify exit events from wxPython using dialog window. One event is from menu exit and the other from frame exit (x symbol in corner). | |
This short code shows how to indicate the mouse-over event on wxPython button, similar to the mouse-over in web pages. Button changes colour when mouse pointer is over its area. | |
The myth is around that while loop is faster than the corresponding for loop. I checked it out with Python module timeit, and came to surprising conclusion. This snippet can easily be modified to time any of your functions you write. | |
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. | |
The program takes text and establishes dictionary of character:frequency. This dictionary is then presented sorted by character. Since it is important to show the most frequent characters, two methods are given to present dictionary sorted by frequency. Should all be very good for learning Python. | |
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 … | |
Do you think that people act demented during full moon nights? This small python program will tell you moon phase of a date you give it, so you can take precautions! | |
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. | |
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 … | |
Question of wordcount program similar to Unix wc came up in the forum and I worked on a solution. Program shows number of lines, number of words, number of characters and text file's name. Good learning for commandline, file and string handling. | |
The little program allows eye patients to test their color skills. They are given a random color rectangle by the computer and are then asked to match the color as closely as they can using sliders of the three basic colors. An evaluation button examines the closeness of the results. | |
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. | |
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. … | |
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] |
The End.