445 Topics
So you want to find out which day of the week you were born. Well at least some of us do. I actually wrote this program because my whole family was born on Sundays, and my friends didn't believe it! An oldie but goodie, moved from DeSmet C to Turbo … | |
A simple way to create rainbow colored text on your web page. Just cut and paste the code into Notepad, save as Rainbow.htm and run it on your browser. | |
In today's environment where just about anyone can snoop around your e-mail, it is prudent to securely encrypt your more private writings. This little Python program will make it easier to do so. | |
Uses the PySide GUI toolkit's QtMultimedia module to play a specified sound. You can change frequency/pitch and volume of the sine wave. | |
This code snppet uses the wx.lib.filebrowsebutton.FileBrowseButton widget to pick a file, in this case a '.wav' sound file, and plays it with the wx.Sound widget. | |
The wxPython Phoenix project can be used with Python version 2 and version 3. The project applies pretty much the familiar wxPython code. Here we are testing a dragable borderless frame. | |
Use onMouseover to change the background color of your webpage. Can be applied to change other things like images and so on. | |
Just a code sample that allows you to play your midi or mp3 music files with Python and module pygame. | |
You can draw a number of shapes directly on the PyGame window, and then save the drawing to an image file. | |
Here is a short Python program using the module pygame that lets you play a midi music file. Midi files are instrumental music files that pack a lot of good sound into a small file. They are very popular with web page designers. ![]() | |
A somewhat newer look at Peter Parente's pywin32 based speech engine. It will read text on your computer. | |
Yes, you can let your computer read text to you. The task is relatively easy, if you have Windows on your machine. All you need is Microsoft's speech-API SAPI, the Python Text to Speech module pyTTS, and an updated version of win32com, all free downloads. Here are some experiments with … | |
This code example shows how to create a dictionary with row,column indexed (r,c) key tuples from a typical list of lists 2D matrix. Also an example is shown of the ease of processing the resulting dictionary. | |
A simple test of PySide's QFileDialog widget and its method getOpenFileNames. Use method getOpenFileName if you want just one file name. | |
Simple code to show you how to display an image from a Web URL using the Tkinter Python GUI toolkit, the Python Image Library (PIL) and the data_stream created with io.BytesIO(). | |
So you want to find out which day of the week you were born. Well at least some of us do. I actually wrote this program because my whole family was born on Sundays, and my friends didn't believe it! An oldie but goodie, moved from DeSmet C to Turbo … | |
This short piece of code shows you how to display text in color in a C# windows console program. The corresponding WIN32 API functions are in the kernel32.dll and are imported and declared external. The only other problem is to assign variable types that accommodate the types listed in the … | |
A permutation is the arrangement of a set of items in different order. One interesting application is the rearrangement of characters in a word to create other words. If all the n characters are unique, you should get n! unique permutations. You can make a list of words unique by … | |
Scientists and deficit spenders like to use Python because it can handle very large numbers. I decided to give it a test with factorials. Factorials reach astronomical levels rather quickly. In case you can't quite remember, the factorial of 12 is !12 = 1*2*3*4*5*6*7*8*9*10*11*12 = 479001600, that is 479 million … | |
This snippet allows you to find the number of ordered permutations of items taken from a population of known size. It uses the well know algorithm with factorials. For very large populations you may want to use an approximation of factorials. | |
If you want to know the number of combinations of x things taken n at a time, you can use the Python module gmpy. The module gmpy is a C-coded Python extension module that supports fast multiple-precision arithmetic, very handy if x things reach a large number. | |
This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks. | |
Let's imagine you are taking a lot of pictures and modify them with one of those fancy image editors. You burned the image files to a CD, and decided to purge some of the outdated files because your hard drive is getting full. This Python code allows you to set … | |
A simple code example to calculate the monthly payment on a mortgage loan. Takes a look at Python's newer print and format functions. | |
Just a different way to extract desired data from an xml code string. | |
A short code to show you how you can download and display an image from the internet on Python's Tkinter GUI toolkit. | |
Just a simple Jython code to test drawing on the canvas. | |
A small test program exploring the PySide/PyQT Label widget. With HTML code you can do some nice formatting of the label's text. | |
The PySide/PyQT QValidator restricts the type of input a widget like QLineEdit can accept. Here is a simple test. | |
Another exercise in applied geometry. This time we use the Tkinter GUI canvas and its create_line() function to draw a triangle, or a series of connected triangles to create something that looks like fancy art work. You might be able to impress grandmama with that one! | |
A function to take a text and extract the string between two given substrings. Allows you to find the nth occurence. Also safeguards against dead ends. | |
You may want to call Python's list the answer to other computer languages' arrays. Here we take a look at the things you can do with lists, create an empty list, list the attributes and methods, load, append, count, insert, join, pop, remove, remove duplicate items, reverse, search, sort, establish … | |
This PySide (PyQT) code sample shows you how to apply a StyleSheet to a GroupBox containing a number of RadioButtons. | |
A little fun drawing with the Python module turtle. Well commented to help the beginner. | |
If you draw shapes that are closely spaced and shifted, you can create interesting interference patterns, so called moire patterns. Here is an example using the Python module PyGame to do the drawing. | |
This small code example shows you how to approach the beginning concept of an very simple "IDE" for Python. | |
If you want a window with a menubar, toolbar, statusbar, dock and central widgets, you can use the PySide GUI toolkit's QMainWindow. To use the more traditional box and grid layouts, you simply add a QWidget instance as the central widget. Here is an example. | |
A colorful look at the PySide GUI toolkit and its QPainter class and methods. Well commented and demonstrated with the drawing of a number of rectangles and the different ways to apply colors. | |
A Python code example to find an approximate value for x in f(x) = 0 using Newton's method. | |
Explore Python's sqlite3 database module, create, write and read a database file. | |
This snippet shows you how to create a list of class instances. The class itself cannot be pickled, but the list of instances can. To use the pickled data file in another program, you have to recode the class in that program. | |
Jython is a version of Python that can use the extensive Java library. Jython uses Python syntax and avoids the rather ugly syntax (at least for Pythonions) of Java. Here we apply it to bring up an image from a file. | |
This Python code allows you to get selected statistics of a story text. It will count lines, sentences, words, list words and characters by frequency, and give the average word length. It should be easy to add more statistics using the dictionaries created. | |
You can alternately show one of two lines drawn on the Tkinter canvas by simply moving them on and off the canvas screen. This beats a cumbersome create and delete cycle. | |
A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows. | |
Comparing a number of different approaches to finding the closest pair of numeric elements in a list. The timing is done with the mpmath module, but you can also use Python module timeit. | |
Python is entirely object oriented and using classes is made relatively simple. Beginners have a certain angst when it comes to using classes. There is a hump in the learning curve, which I like to overcome with this example. Inheritance really makes sense and saves you a lot of extra … | |
An approach to create multiple GUI buttons (or other widgets) using list comprehension. In this case I used the Tkinter GUI toolkit that comes with the Python installation. | |
Just a small example showing how to draw circles with PySide (public PyQT). I used LightShot to capture the display, which gives you a link to the picture. http://prntscr.com/kw6b6 | |
Let's say you have a whole bunch of nicely named lists and want to save them all and their names in a pickle file. One solution can be to store these lists and their names in a Bag container class and pickle the bag instance object. Now you can use … |
The End.