379 Reusable Code Snippet Topics

Remove Filter
Member Avatar for vegaseat

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 …

Member Avatar for Mark_94
5
6K
Member Avatar for vegaseat

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.

Member Avatar for Dani
2
74K
Member Avatar for vegaseat

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 …

Member Avatar for CodeWorked
1
22K
Member Avatar for vegaseat

For those who are afraid of lycanthropes and full moons, here is a way to figure out the phase of the moon.

Member Avatar for Sichen
2
6K
Member Avatar for vegaseat

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 …

Member Avatar for laheg
2
25K
Member Avatar for vegaseat

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 …

Member Avatar for Djcordeiro
2
4K
Member Avatar for vegaseat
Member Avatar for paddy3118
1
2K
Member Avatar for vegaseat

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 …

Member Avatar for amir_19
3
24K
Member Avatar for vegaseat

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.

Member Avatar for Webtest
1
14K
Member Avatar for vegaseat

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 …

Member Avatar for bunkus
2
4K
Member Avatar for vegaseat

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 …

Member Avatar for Vinay_17
2
26K
Member Avatar for vegaseat

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 …

Member Avatar for JamesCherrill
5
10K
Member Avatar for vegaseat

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.

Member Avatar for woooee
4
25K
Member Avatar for vegaseat

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.

Member Avatar for iman_1
1
5K
Member Avatar for vegaseat
Member Avatar for Daniele_2
4
19K
Member Avatar for vegaseat

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.

Member Avatar for Marc_10
7
13K
Member Avatar for vegaseat

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.

Member Avatar for Gribouillis
3
2K
Member Avatar for vegaseat

This code creates a sound file in Sun's simple AU audio format of a sine wave of given frequency, duration and volume.

Member Avatar for samson.dadson.3_1
1
2K
Member Avatar for vegaseat

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 …

Member Avatar for Abdullahi_2
3
11K
Member Avatar for vegaseat

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!

Member Avatar for Rufus_1
5
12K
Member Avatar for vegaseat

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) …

Member Avatar for neon_3
1
23K
Member Avatar for vegaseat

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 …

Member Avatar for Charles_24
5
10K
Member Avatar for vegaseat

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 …

Member Avatar for rproffitt
1
6K
Member Avatar for vegaseat

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.

Member Avatar for Johannes_2
0
5K
Member Avatar for vegaseat

A little fun with Python's turtle module drawing a number of random stars in the dark sky.

Member Avatar for Ali_65
2
11K
Member Avatar for vegaseat
Member Avatar for vegaseat

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 …

Member Avatar for Viresh_2
0
9K
Member Avatar for vegaseat

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 …

Member Avatar for Gribouillis
2
125K
Member Avatar for vegaseat

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.

Member Avatar for toyota_1
0
12K
Member Avatar for vegaseat

If you have a long message to display in a large readable font, then this little Tkinter GUI toolkit code might help.

Member Avatar for Mohamed_65
1
4K

The End.