IronPython revisited (99 bottlse of beer)


If you use the Windows OS, then IronPython allows you to create a GUI program taking advantage of the .NET framework. You also have the option to compile the program into a standalone .exe file (and the needed .dll file).

About the Author


add '99 bottles of beer' lyrics to a .NET list box
simplified code using some defaults

IronPython gives access to the Windows .NET or Linux Mono libraries
download the IronPython installer version 2.7.3 from

run with the IronPython interpreter this way ...
(might have to add full path)

tested with IronPython 2.7.3 by  vegaseat  28may2013

import clr


import System
from System.Windows.Forms import *
from System.Drawing import *
from System.Collections import ArrayList

class BeerSong(Form):
    def __init__(self):
        # width, height of form
        self.ClientSize = System.Drawing.Size(220, 326)
        self.Text = '99 BoB lyrics'
        # create the listbox and fill the form (self) with it
        box = ListBox()
        # light yellow
        box.BackColor = System.Drawing.Color.FromArgb(255, 255, 224)
        box.Dock = DockStyle.Fill

        # move the lyrics into ArrayList then transfer to the box
        array = ArrayList()
        bottle = "%s bottle"
        beer = "s of beer on the wall!"
        take = "Take one down, pass it around,"
        for k in range(99, 0, -1):
            # an exercise in slicing
            s1 = bottle % k + beer[k==1:]
            s2 = (bottle % k + beer[k==1:])[:-13] + "!"
            s3 = bottle % (k-1 or "No")
            s4 = beer[k==2:-1] + "!"
            array.Add(" ")
        box.DataSource = array

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The above IronPython script can be compiled to a standalone .exe file this way ...

compile an ironpython sript file to an executable file
creates a Windows .exe file and an associated .dll file
in this case ...
ip_ListBox_99BoB.exe  (3kb)
ip_ListBox_99BoB.dll  (13kb)

it is best to put this file into a special directory
together with the ironpython script file you want to compile

this code needs to be run with IronPython 2.7.3

import subprocess

# the ironpython script file you want to compile ...
ip_scriptfile = ""

# location of ironpython and compile utility
ipython = "C:/IronPython2.7.3/ipy.exe"
utility = "C:/IronPython2.7.3/Tools/Scripts/",
main = "/main:" + ip_scriptfile
target = "/target:winexe"[ipython, utility, main, target])
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I have read that Microsoft has withdrawn support for IronPython. I guess they have grown worried about the popularity of Python (not one of the languages under their control).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.