629 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
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 Reverend Jim

I wrote a timer/alarm app in Python that I wanted to be accessible from all Windows Desktops. What I had to do until recently was run the app, select the desktops icon on my toolbar, then right click the app and select "Show this window on all desktops". I was …

Member Avatar for AndreRet
2
837
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 Liam_12

Am at an intermediate level in python and tkinter, and have been trying to figure out how to get the code below into some kind of workable form I can understand. What I want to do is, like, if I typed something into the bottom frame, then I'd like to …

Member Avatar for Husoski
0
172
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 bruce.hagen

I have a Py file that consists of 100+ frames, aprox 80+ radio buttons and 65 textboxes. I have attached shortened exert from main file. Textbox 1 takes on a value when a radio button is pressed. When button "Show Values is pressed it inserts the accumulated of all textboxes …

0
185
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 Reverend Jim

Sometimes you want to ensure that only one copy of a script can be run at time. Windows provides a facility called a mutex and you can use it to prevent multiple instances. To create the mutex, all I have to do is varname = GetMutex() If the mutex already …

1
2K
Member Avatar for Reverend Jim

##This project implements a multiple timer application. It was written in 1. Python 3.8.2 2. wxPython 4.1.0 Feel free to experiment. Here are some possible enhancements: 1. Add the ability to run a program when the timer expires. With a little scripting you could, for example, schedule the sending of …

2
1K
Member Avatar for madDOGim

I solved a problem some day ago. In that problem you had to format an integer. I found it hard to solve. So here I am sharing my problem with you. Problem: Read an integer variable and print it in which the digits are separated into groups of three by …

Member Avatar for Koos_1
2
709
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 Tanuj_2
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 HiHe
Member Avatar for martineau
1
21K
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
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 TrustyTony

This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets.

Member Avatar for Gribouillis
0
5K
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 Gribouillis

This snippet defines a function restart_program() which restarts your python program from within your python program.

Member Avatar for Gribouillis
5
75K
Member Avatar for Tcll

**Usage:** Provides a secure frontend object with restricted access to attributes of the backend object.

Member Avatar for Gribouillis
0
437

The End.