Programming assignment - Tuesday Dec 6 2005

Binary symmetric channel G.U.I.

A GUI (graphical user interface) is a piece of software that provides the user with pretty buttons to click and sliders to drag.

GUIs sometimes help teaching. They impress some people too. They may even be useful for real work.

Today, you will make a GUI that simulates a binary symmetric channel. Your GUI should look something like the picture on the right. When you click on the buttons, something should happen!

To help you solve this problem, we will provide you with another working GUI that solves a different problem. This is a GUI that implements Alan's lightbulbs problem. Here's a picture of it.

You can copy the source code for this GUI from

  ~mackay/python/switches/switches5.py  
and you can run it by using, for example:
  python ~mackay/python/switches/switches5.py 

This program is quite long. You may find it easiest to look first at some simpler programs, which implement just parts of the GUI. Try these, for example:

  python ~mackay/python/switches/switches.py 
  python ~mackay/python/switches/switches2.py 
  python ~mackay/python/switches/switches3.py 
  python ~mackay/python/switches/switches4.py 


Hint

You will need to know how to make the "Scale" (the noise level slider). Here is a possible piece of python code

  f = DoubleVar()
  fscale = Scale( root, label="Noise level", variable=f, \
                 from_=0.0, to=1.0,resolution=0.01, orient="horizontal",sliderlength=25, length=250)
  fscale.grid( row=10 , column=0 , columnspan=8  )
You will need to use the value of the double variable f also. Here is an example piece of code, which compares a random number with f.
	random()<f.get()
Notice that, to find the value of a DoubleVar, you have to ask it nicely by using its ".get()" method.


An introduction to the tkinter package, which provides buttons, scales, and other things | More information about the tkinter package. Look at the 'patterns' to find examples.

Python notes en francais (4M, 370 pages) (copied from www.ulg.ac.be)


Solution

  python ~mackay/python/switches/secret/bsc.py 

/ David's Home page / David's Python page /