379 Reusable Code Snippet Topics
Remove Filter Using PySide's QAbstractTableModel allows you to easily customize a widget like QTableView and make it more generic in its application. Here we use it to present solvent data in tabular form and sort each column content by simply clicking on the header. You can feed it any data as long … | |
Things don't have to be black and white all the time. Use a Windows API call to add some color to your text output. | |
The Tkinter module comes with the normal Python installation. It allows you to create Python GUI programs for Windows, Linux or Unix on the Mac. In this snippet we put a GIF image (.gif) onto a form's canvas with just a few lines of code. Most of the lines are … | |
For those who are afraid of lycanthropes and full moons, here is a way to figure out the phase of the moon. | |
What "Hello World" is to the console, the "Bouncing Ball" is to the Graphical User Interface. Nothing fancy, the ball is created via a call to the API function ellipse() and then bounced within the confines of the windows form. For the DEV C++ crowd: Let me know if you … | |
The printer seems to be a much ignored computer peripheral when it comes to programming. This little code snippet explores one way to send text to the default printer. It actually draws the text into an imaginary box on the paper. You can specify the upper left and lower right … | |
Just trying to find out which of these five isprime functions is the fastest. | |
This simple isprime(number) function checks if the given integer number is a prime number and returns True or False. The function makes sure that the number is a positive integer, and that 1 is not considered a prime number. To find out if an integer n is odd one can … | |
If you press any key on your keyboard, this small Tkinter GUI program will tell you which key and what type of key has been pressed. Great for applications where a simple key stroke is required. | |
An example showing how to use the wx.media.MediaCtrl() widget to play MIDI, MP3, WAV, AU, AVI and MPG audio and video files. I have only tested it with Windows. If you are very ambitious, you could use a random graphics display with the sound, or tie the slider position to … | |
This short Python code gets the local time from the PC as a formatted string using time.strftime('%H:%M:%S'). The time string is displayed in a label using a larger font. A recursive function checks the time five times per second, and updates the time string, if it has changed. Five times … | |
Let's say you want to send a short private message to your friend, but don't want grandma to snoop around and find it. One way is to use the Python Image Library (PIL) and hide the message in a picture file's pixels. Just looking at the picture you will barely … | |
This code shows how to obtain and display a GIF image from an internet website using the Tkinter GUI toolkit that comes with the Python installation. | |
The snippet shows how to create a menu on a windows form and test it. Original code via BCX, modified to compile with Dev C++ as a Windows Application. This approach does speed up writing of GUI programs. | |
Shows how to create a basic slide show with the Python Tkinter GUI toolkit. | |
This class gives a specified Tkinter widget a tooltip that appears as the mouse is above the widget. You can improve the code by putting in a time delay. | |
PySide (public license PyQT) is my preferred Python GUI toolkit. Here we explore how to test some of the widgets available and create a digital clock. | |
This code creates a sound file in Sun's simple AU audio format of a sine wave of given frequency, duration and volume. | |
Sometimes when you get a large check from your employer, the value is written out in words. I get those all the time of course. So I wrote this little Python code to convert an integer value to english words. Numbers as high as 999 vigintillion can be used. In … | |
Another application of Python module base64, this time to embed midi music data in your program. You also need the module pygame to execute this Python code. Enjoy the music! | |
You can put an image and text on a Tkinter button widget. This small code shows you how. The GIF image file you want to use for the button should be in the working directory, or you have to give it the full path. Incorporate the Python Image Library (PIL) … | |
Just a relatively simple calculator using the Tkinter GUI. It has a few nice features such as correcting division by an integer (for older Python versions), error trapping, to and from memory buttons, and an editable display. The editable display allows you to backspace mistakes, and also to enter things … | |
A little calculator written in BCX basic and then translated to C code and modified to compile with Dev C++ (GCC/G++). Once you find your way past the standard GUI gibberish you can figure it out. For those who need some hand holding with the Dev C++ IDE: In the … | |
Lots of good instrumental music out on the web in the form of midi files. You can incorporate background music as part of your web page. Here is the short code. | |
A little fun with Python's turtle module drawing a number of random stars in the dark sky. | |
A short example of Pygame showing an image with a known internet url. | |
Use Python module threading to count intervals (in seconds) in the background. You can use this to time any relatively slow event like the time it took to finish a game or play some music. You can also peek at the current interval value as the event goes on. Go … ![]() | |
A list of class objects mimics a C array of structures. The snippet explores how to setup the list, and sort the list according to a selected attribute. Then we use a format string to display the sorted list. Take a look at how to search the list. All in … | |
The Tkinter GUI toolkit comes with a scrolled text widget that is called ScrolledText. To get access to it you have to import it separately. It allows you to display large amounts of text in a small space. | |
If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help. |
The End.