445 Topics
If you draw a series of close spaced shapes your eyes get fooled to see Moire patterns. Here is one example of this. | |
Just in time for the season, a star. (Playing with my grandson on the Raspberry Pi computer) | |
Once you are on the internet, you have to come up with passwords. After a while it will be difficult to remember those passwords. You could write them down somewhere, but the wrong person could find them. Why not have Python help you to come up with a logical password … | |
This snippets shows how to have fun replacing multiple words in a text. The target words and the replacement words form key:value pairs in a dictionary. The search and replacement is done using Python's regular expression module re. The code also gives an example of a function within a function. | |
An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years. | |
For those of you who are inquisitive, here is a little Python program to approximate the value of pi to 77 digits. You can easily go further, just change the value n in range(n+1). | |
This snippet shows you how to animate a dice roll with the Tkinter GUI, useful for many games that require a dice to give a random number from 1 to 6. An interesting use of Tkinter's grid(), grid_forget() and after() functions. | |
Just the very basics on how to draw a rotated text using the Python GUI toolkit PySide (public PyQt). Please experiment and embellish. | |
With the advent of Python33 the module time has received a high resolution timer/counter. Here we use time.perf_counter() in a decorator to conveniently time two test functions. | |
The idea of this thread is to help the beginning wxPython GUI programmer with hints and helpful code. Please feel free to contribute! If you have any questions start your own thread! For info on wxPython modules see: http://www.wxpython.org/docs/api/wx-module.html | |
Run two calls to a function simultaneously with this threading @background decorator. | |
Similiar to the snippet posted at: http://www.daniweb.com/software-development/python/code/449036/display-an-image-from-the-web-tkinter but this time we use PIL to resize the image from the internet keeping its aspect ratio to fit a specific display area/box. | |
The Pyside GUI toolkit (public PyQt) lets you bring up an interactive web page with its QWebView widget. Here is a simple example. | |
The portable version of Python (versions 2.7 and 3.2 are available) can be run from your hard drive or a flash drive. In many ways this makes your live easier, since a lot of libraries are included already. Also, you can take your code to a friend on a flash … | |
This short Python program calculates Euler's number e, the base of natural logarithms, to a precision of at least 100 digits in this case. To get the precision needed, the Python module decimal is used. The result is compared to a published result. | |
This simple code shows how to write text with a given font, font size and color using the module pygame ... | |
A Tkinter image button that toggles between an up and down button image. | |
This program takes a text string and creates a list of words. Any attached punctuation marks are removed and the words are converted to lower case for sorting. Now you can generate a dictionary of the words and their frequencies. The result is displayed using a sorted list of dictionary … | |
The Fibonacci series of numbers was used by Leonardo of Pisa, a.k.a. Fibonacci (around the year 1200), to describe the growth of a rabbit population. The series has been noted to appear in biological settings, such as the branching patterns of leaves in grasses and flowers. We take a look … | |
Because of their demand only nature, generators are ideal for finding the combinations of larger sequences. This code applies a Python generator to find the combinations of the sequence. Since permutations are a special case of combinations for all the items in a sequence, I have expanded the result to … | |
This AVI file player has some nice features like adjusting size and speed. The program uses the standard MSvfw32.lib (called libmsvfw32.a in the DevCPP lib directory). Another example of using BCX to translate to C code and modify to something Dev-C++ can handle. Enjoy!!! | |
If you use the Windows OS, then IronPython allows you to create a GUI program taking advantage of the .NET framework. You also have the option to compile the program into a standalone .exe file (and the needed .dll file). | |
Using the Python Image Library (PIL) you can resize an image. Several filters can be specified. ANTIALIAS is best for downsampling, the other filters work better with upsampling (increasing the size). In this code snippet one image of each filter option is saved, so you can compare the quality in … ![]() | |
This handy little utility determines the size of a folder and it's subfolders in MBytes. | |
Here is an example on how to put at least lines and circles onto your windows console display. Yes, you have to jump through a hoop to do it. Dev-C++ can do this thanks to some BCX generated code. You have to set up your project as a Console Application … | |
Shows you how to play sound files with the pySFML module and Python. | |
This is an example of a singly linked list allowing you to enter a number of names and associated ages. The twist is that the names are inserted into the list in ascending order. When the list is displayed, it is already sorted by name. Note: This is not an … | |
The PySide (PyQT) GUI toolkit can be used to play wave sound files. | |
PySide's QWebView can load a given url and display the web page associated with it with just a few lines of code. | |
Shows you how to get a Python object's memory size. Notice that there can be a difference between Python versions. | |
If you decorate a function, then some of the information is lost during the debugging process. Python supplies another decorator @wraps to help out. A decorator for a decorator, very interesting. | |
Shows you how to create multiple Tkinter buttons in a loop, each with its own name, label and command response. | |
The code sample shows how to get an image from the internet and show it in a Tkinter label widget. | |
Just a simple image file slide show using PySide (PyQT). | |
This example calculates timed x, y points of a projectile motion that can be used for plotting or other calculations. | |
A Python sort with a helper function to allow for mixed order sort like age descending and weight ascending. | |
Just another loan calculation, this time using a handy function in Python module numpy. | |
Starting with Python 3.3 you now have access to a high resolution time counter (nanoseconds and better). | |
Python module turtle makes it simple to draw graphics art similar to art done by the Logo language. | |
Using Python module turtle to draw a Koch snow fractal. | |
A simple way to find duplicate words in a text. In this case the text is preprocessed to eliminate punctuation marks and set all words to lower case. | |
In Las Vegas random numbers move billions of Dollars in and out of gamblers' pockets. For the mildly inquisitive here is a test of three simple generators. | |
An example how to plot the function y = sin(x) using the WinApi function SetPixel(). The plot is centered along a line at pixel y = 200. Add an x-axis and a couple of tickmarks and it could look impressive. | |
Just a little fun with Python's named tuple, behaves like a class but is much leaner. | |
Applying the famous Gauss algorithm to determine the date of Easter for a given year. | |
Factorials get large very rapidly. The factorial of 13 is !13 = 1*2*3*4*5*6*7*8*9*10*11*12*13 = 6227020800. This number already exceeds the unsigned long integer, and gets into the real money as the politicians say! This program uses an array of characters to store the factorial as a numeric string. Go ahead, … | |
Using the PySide GUI toolkit will make selecting, copying and pasting encrypted and decrypted text somewhat easier. Not ideal yet, but it will be a good start for those of you who are not very familiar with GUI programming. | |
This short snippet shows you how to preprocess a text to remove punctuation marks, then do a word frequency count using Counter() from the Python module collections. Finally, two sorts are applied to display words with matching frequency in alphabetical order. | |
The code shows you how to create a persistent to file dictionary of data using the python module shelve. | |
The End.