417 Archived Topics

Remove Filter
Member Avatar for vegaseat

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.

Member Avatar for diliupgabadamudalige
0
5K
Member Avatar for vegaseat

A somewhat newer look at Peter Parente's pywin32 based speech engine. It will read text on your computer.

Member Avatar for ZZucker
3
307
Member Avatar for vegaseat

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 …

Member Avatar for ZZucker
1
2K
Member Avatar for vegaseat

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.

Member Avatar for TrustyTony
5
6K
Member Avatar for vegaseat

A simple test of PySide's QFileDialog widget and its method getOpenFileNames. Use method getOpenFileName if you want just one file name.

3
3K
Member Avatar for vegaseat

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().

Member Avatar for vegaseat
3
4K
Member Avatar for vegaseat

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 …

Member Avatar for jnawrocki
3
1K
Member Avatar for vegaseat

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 …

Member Avatar for KrayZVIII
0
1K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
1
6K
Member Avatar for vegaseat

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 …

Member Avatar for sneekula
2
5K
Member Avatar for vegaseat

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.

3
3K
Member Avatar for vegaseat

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.

3
475
Member Avatar for vegaseat

This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks.

4
3K
Member Avatar for vegaseat

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 …

Member Avatar for Ene Uran
0
539
Member Avatar for vegaseat

A simple code example to calculate the monthly payment on a mortgage loan. Takes a look at Python's newer print and format functions.

4
9K
Member Avatar for vegaseat
Member Avatar for HiHe
3
641
Member Avatar for vegaseat

A short code to show you how you can download and display an image from the internet on Python's Tkinter GUI toolkit.

3
329
Member Avatar for vegaseat
3
601
Member Avatar for vegaseat

A small test program exploring the PySide/PyQT Label widget. With HTML code you can do some nice formatting of the label's text.

5
749
Member Avatar for vegaseat

The PySide/PyQT QValidator restricts the type of input a widget like QLineEdit can accept. Here is a simple test.

1
714
Member Avatar for vegaseat

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!

Member Avatar for vegaseat
1
3K
Member Avatar for vegaseat

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.

2
1K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
3
415
Member Avatar for vegaseat

This PySide (PyQT) code sample shows you how to apply a StyleSheet to a GroupBox containing a number of RadioButtons.

3
3K
Member Avatar for vegaseat

A little fun drawing with the Python module turtle. Well commented to help the beginner.

3
289
Member Avatar for vegaseat

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.

2
728
Member Avatar for vegaseat

This small code example shows you how to approach the beginning concept of an very simple "IDE" for Python.

0
808
Member Avatar for vegaseat

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.

2
3K
Member Avatar for vegaseat

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.

1
1K
Member Avatar for vegaseat
Member Avatar for dashing.adamhughes
2
7K
Member Avatar for vegaseat
3
345
Member Avatar for vegaseat

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.

3
2K
Member Avatar for vegaseat

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.

4
721
Member Avatar for vegaseat

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.

Member Avatar for Ene Uran
3
804
Member Avatar for vegaseat

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.

3
535
Member Avatar for vegaseat

A closer look at the Tkinter GUI toolkit Toplevel Window and how to lift and lower it respective to other windows.

0
6K
Member Avatar for vegaseat

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.

Member Avatar for Lardmeister
5
756
Member Avatar for vegaseat

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 …

Member Avatar for Ene Uran
0
1K
Member Avatar for vegaseat

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.

Member Avatar for Ene Uran
2
484
Member Avatar for vegaseat

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

2
10K
Member Avatar for vegaseat

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 …

Member Avatar for Lardmeister
4
253
Member Avatar for vegaseat

A real useful piece of code, hence I put it under Z. It does nothing but open and close the door of the CD-ROM player, and pushes the tray in and out. Should your coffee be too hot, you can put it on the moving tray and cool it off! …

Member Avatar for RonalBertogi
1
652
Member Avatar for vegaseat

If you have a smaller image, you can include it in your program as a base64 encoded string. This way you don't have to worry about an image file to go with your code. In your program you can then decode it back to the familiar bytes of an image …

Member Avatar for HiHe
5
8K
Member Avatar for vegaseat

Python experiment to get an image from a web page and save it to an image file. Updated code to work with both Python versions ...

Member Avatar for snippsat
5
2K
Member Avatar for vegaseat

[B]Intro[/B] C is using structures to group data, mostly data that belongs together. Here we have some data that a campaign manager might keep for the volunteers. First we take a look at the C code: [code=c]#include <stdio.h> struct person { char *name; char *sex; char *slogan; }; int main(void) …

Member Avatar for georgooty
0
767
Member Avatar for vegaseat

This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape.

2
4K
Member Avatar for vegaseat

There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ...

Member Avatar for rubik-pypol
3
396
Member Avatar for vegaseat

I am exploring some of the PySide (PyQT public) widgets like the combo box, and how colors are applied ...

2
2K
Member Avatar for vegaseat

This Python code shows you how to get a current list of currency values (Canadian Dollar = 1.00) via the internet.

Member Avatar for TrustyTony
0
494
Member Avatar for vegaseat

The Tkinter library folder \lib-tk contains a module called turtle. You can import this module and experiment with turtle graphics. Tell the turtle to move and draw circles, lines, rectangles and more, and watch it, as it performs on a Tkinter canvas. In typical turtle fashion it moves at its …

Member Avatar for woooee
0
2K

The End.