445 Topics

Member Avatar for vegaseat

Python programming can have its lighter moments. Here we use one of those moments to draw an optical illusion using the Tkinter canvas to draw a rectangle, some lines and circles.

2
723
Member Avatar for vegaseat

Do I have to spell it out for you? This short C code will do just that. It will spell out an integer number in English words. The banks do that on large checks, and it would be nice to get one of those every now and then.

Member Avatar for soulcandra44
1
525
Member Avatar for vegaseat

The code is shamefully short, but here it is. Now you can listen to the many sound files in wave (.wav) format and boing, chirp, chime, bark, booh, laugh and mooh at the people around you.

Member Avatar for jbronen
3
1K
Member Avatar for vegaseat

A simple program to count the words, lines and sentences contained in a text file. The assumptions are made that words are separated by whitespaces, and sentences end with a period, question mark or exclamation mark.

Member Avatar for snippsat
2
2K
Member Avatar for vegaseat

The wxPython GUI toolkit makes a very nice plotting component/widget available. You can select line or marker plotting, or a combination of both. All you have to supply is a list of x,y point tuples. Other features include zooming and printing.

Member Avatar for aernie
1
2K
Member Avatar for vegaseat

Write a Python program that creates upside down sentences, like [B] upside down --> umop apisdn [/B] The sentence above is flipped 180 degrees around the end. Some freedom allowed, like an 'a' upside down and reversed is the closest thing to an 'e'. Conversely a 'w' would be a …

Member Avatar for TrustyTony
0
1K
Member Avatar for vegaseat

Let Python do the work for you and figure out the roman numerals for a given integer. I have to ask you to keep the integer values somewhat reasonably low (from 1 to 4999), since roman numerals from 5000 on use characters with an overline and most PCs don't have …

Member Avatar for eljakim
0
3K
Member Avatar for vegaseat

Just spent about an hour removing [B]Antispyware Soft[/B], a small miserable program that comes in on e-mail or certain church sponsored web sites. It deposits a random named executable in your Windows OS (XP through Windows7) and then takes over the registry to a point where you can not run …

0
93
Member Avatar for vegaseat

Starting with version 2.6 Python has introduced a new container called the named tuple. You can use it similar to a class based record structure, but it has the memory efficiency of a tuple.

1
2K
Member Avatar for vegaseat

The Python module 'tarfile' is more flexible then it's counterpart 'zipfile'. It allows you to simply archive files without compression, or use the gzip format of compression, or the super compression format bzip2. Here is code to show you the use of the module.

Member Avatar for vegaseat
3
2K
Member Avatar for vegaseat

A short look at creating lists of file names or full path names using the versatile Python module glob. Glob follows the standard wildcard protocol.

1
3K
Member Avatar for vegaseat

A little late for April 1, but here is the secret code ... [code]searchEngineNames = [] for c in range(ord('A'), ord('Z')+1): name = chr(c)+'ing' searchEngineNames.append(name) # pick #1 print(searchEngineNames[1]) [/code]

Member Avatar for TrustyTony
4
110
Member Avatar for vegaseat

Looking at the First In First Out (FIFO) data situation. Just like a line at the grocery store check-out. Its counterpart FILO would be like a stack of dinner plates.

Member Avatar for mitrmkar
2
233
Member Avatar for vegaseat

A demo of the Tkinter listbox widget that shows you how to create the listbox, make it scrollable, position it within a grid, load it with data from a file, select a line of data with the mouse and display it. Also, sort the lines, add a line, delete a …

Member Avatar for Tcll
3
15K
Member Avatar for vegaseat

We take a look at the various functions of module time, counting seconds and milliseconds, measuring the time a simple for-loop takes, inspect a list of time data and ways to display it in a useful manner. An attempt is made to find the day of the week, given a …

Member Avatar for Kanem
2
2K
Member Avatar for vegaseat

You can use Python modules math, wave, and struct to create and save a synthetic sine wave of given frequency and duration (size) ...

1
3K
Member Avatar for vegaseat

Wallpaper or tile images are small images that can be spread across a background repetitively. A common practice on web pages. The surface created with wx.PaintDC() can be used for this effect and still allows other widgets to be put on top of the wallpaper. The small tile image is …

Member Avatar for vegaseat
1
984
Member Avatar for vegaseat

A lotto simulator with a twist, you pick the winning numbers and the computer buys the lotto tickets. Anyway, the computer at least generates the tickets and checks how many of them would match the winning numbers you selected. Let's assume you would be the state lotto commissioner and your …

Member Avatar for lyndon enero
0
7K
Member Avatar for vegaseat

Convert a decimal (denary) integer to a binary string. An exercise in do ... while and while loops.

Member Avatar for arun26
2
2K
Member Avatar for vegaseat
Member Avatar for vegaseat
0
97
Member Avatar for vegaseat

This is an update of an earlier version. In this version the string containing the approximated pi value is created directly from the iteration of the generator. This way the program is simplified and can be used with Python2 and Python3 ...

1
593
Member Avatar for vegaseat

Python uses the Mersenne Twister as the core random generator. The module random contains a fair number of methods (or functions) that help you to do random things. Here are some examples ...

Member Avatar for sainandan
1
221
Member Avatar for vegaseat

The module tkSnack from our friends at KTH in Stockholm, Sweden allows you to play a variety of sound files using the Tkinter GUI. Supported sound files are WAV, MP3, AU, SND and AIFF formats.

Member Avatar for yvos91
0
1K
Member Avatar for vegaseat

Here we apply the module difflib to compare two texts line by line and show the lines of the first text that are different from the second text.

Member Avatar for jimothy
0
236
Member Avatar for vegaseat

This program uses the Python win32 extension module to get information on disk or flash drives for Windows machines. Specify the drive with its letter. If no drive letter is specified, the current drive is applied.

Member Avatar for Gribouillis
4
3K
Member Avatar for vegaseat

The World is due another attempt at a universal language. So what are your ideas? My proposal: Easy to learn (simple grammar). Use a simple alphabet (no umlauts please). Make the most common words the shortest words. The words should be unique in sound and somewhat melodic. Pronunciation should make …

Member Avatar for Brian Barker
0
239
Member Avatar for vegaseat

This code snippet shows you how to sort more complicated objects like a list of lists (or tuples) by selecting an index of the item to sort by.

Member Avatar for Ene Uran
2
375
Member Avatar for vegaseat

Here is an example I was thinking of ... [code=python]import random import time def delay(seconds): time.sleep(seconds) def shuffle_hitlists(my_hitlist, mo_hitlist): """shuffle the two lists and return the result""" random.shuffle(my_hitlist) random.shuffle(mo_hitlist) return my_hitlist, mo_hitlist def battle(my_hitlist, mo_hitlist, my_strength, mo_strength): # player starts swinging first for k in range(len(my_hitlist)): my_hit = my_hitlist[k] mo_hit …

Member Avatar for python user
0
736
Member Avatar for vegaseat

A function that takes a string and returns the number of words in the string. An example of using pointers in Pascal.

Member Avatar for BitFarmer
0
2K
Member Avatar for vegaseat

Python can use its COM support and the OCX of the WindowsMediaPlayer to play mp3 music files. Make sure that your Python installation has the win32com folder. Check [url]http://starship.python.net/crew/mhammond/win32/Downloads.html[/url] for the latest win32com support. [COLOR="Red"]This code relies on file WMPlayer.OCX which MS has removed on newer versions of Windows. See …

Member Avatar for vegaseat
1
2K
Member Avatar for vegaseat

This shows how to create, load and access a ListBox. BCX was used to create the original code which was then modified to work with the Dev C++ (really GCC/G++) compiler, compile as a Windows Application.

Member Avatar for lashatt2
0
1K
Member Avatar for vegaseat

A small Windows Application to show you how to play a wave (.wav) sound file. I am using the C# IDE from SharpDevelop and the runtime dotnetfx 1.1 from Microsoft, both free downloads. This forms a small and fast student system to write and debug C# programs. From there you …

Member Avatar for ashley dane
0
1K
Member Avatar for vegaseat

Python has some powerful functions, like the math expression evaluator eval(). You can embed this function and others in your Development C++ code. All you need to do, is to download and install the free Python Development Pak and feed the Python code in the form of a string to …

Member Avatar for Shantha.D
1
5K
Member Avatar for vegaseat

Tired of the Tk icon in the corner of the form. It's easy to replace with any fancy icon you have. Here is the code ...

Member Avatar for The-IT
0
1K
Member Avatar for vegaseat

An example of a range generator that handles floating point numbers, appropriately called frange(). The function range() or the generator xrange() can only be used for integers. Note that xrange() now is range() in Python3.

3
734
Member Avatar for vegaseat

Ever since I upgraded to IE8 I have noticed the beast freezing up more frequently than the usual Windows software. I have switched to Firefox and found that web browser a lot more stable than even IE7. Is there any software for converting "IE favorites" to something useful like an …

Member Avatar for Ezzaral
0
73
Member Avatar for vegaseat

Here is an example how to write a program to convert between units of distance, area, volume, weight, pressure, and energy. The wxPython GUI toolkit's wx.NoteBook() widget is used to make good use of the limited frame/window space available.

3
184
Member Avatar for vegaseat

A variation of the previous bouncing ball code. This time the upper left corner of the image rectangle simply follows the position of each mouse click. Use an image you have, in my case I used a small red ball in a black background. A simple code to experiment with.

3
3K
Member Avatar for vegaseat

Text to speech can be implemented in its simplest form using Microsoft's Component Object Model (COM) connecting to the Speech API (SAPI). The attached Python code shows you how to do this.

0
4K
Member Avatar for vegaseat

This short Python snippet shows you how to read mouse wheel events with the Tkinter GUI toolkit. Windows and Linux have different bindings and read different events, but can be included in the same program code for use with either operating system.

0
21K
Member Avatar for vegaseat

This well commented Python snippet uses wxPython's plotting widget to graph the projectile motion of two different firing angles on the same plotting canvas.

1
276
Member Avatar for vegaseat

Sometimes you want to accomplish something with a minimum ammount of code. Here is an example of using modern Python concepts of lambda, list comprehension and all() to create an anonymous function that returns a prime list from 2 to n.

1
167
Member Avatar for vegaseat

A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget.

0
602
Member Avatar for vegaseat

Just bouncing a red ball within the frame of a window, the twist here is that the image is stored within the code as a base64 encoded string of the gif image. This way you only have to distribute one file. The Python code is heavily commented, so you can …

Member Avatar for Arkapravo
2
374
Member Avatar for vegaseat

Using count() from Python's itertools module and the Tkinter GUI toolkit's after() function, you can create a simple counter that counts up the seconds until the Stop button is pressed.

1
3K
Member Avatar for vegaseat

The wxPython wx.lib.fancytext widget allows you to display super and subscripts in texts, and allows you to change fonts and colours too. All this is done with XML coded strings. XML documentation code is tag based and not that difficult to understand. It looks rather similar to the older HTML …

0
416
Member Avatar for vegaseat

The wxPython GUI toolkit has a number of calendar widgets, but the one that is most customizable is the wx.lib.calendar widget. Here we expanded it to colour the weekends and the holidays supplied by a dictionary of 'month: list of holiday dates in month' pairs. Since some holiday dates can …

0
2K
Member Avatar for vegaseat

Just a little mathematical exercise in geography, namely the use of longitude and latitiude coordinates to calculate the distance between two given cities. You can obtain the coordinates for just about any earthly city from [URL="http://www.ASTRO.COM"]WWW.ASTRO.COM[/URL]. The coordinates are in a format like 35n13 (35 degrees, 13 minutes north). The …

3
2K
Member Avatar for vegaseat

There are times when you have to layout widgets on a window area fairly well spaced apart. To do this with pack() or grid() will be more than frustrating, for these occasions place() with its absolute coordinates comes to the rescue. Here is some Python/Tkinter GUI code showing you how …

1
619
Member Avatar for vegaseat

A short C# code snippet to get the US Naval Observatory Master Clock Time from: [URL]http://tycho.usno.navy.mil/cgi-bin/timer.pl[/URL] The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone.

Member Avatar for Mustafa Laith
0
684

The End.