Craft 9

Beautiful Code
Ka-Ping Yee

Make sure you understand the material in Explore 9 before you do this assignment.

Eins

For this part, design the interface to a music player. You get to decide what buttons and labels you are going to have (such as play, stop, forward, shuffle, song name, and so on). Come up with a pleasing arrangment for the interface, and construct the interface using Tkinter. You'll probably want to sketch it on paper before you try to build it on the computer.

Your program doesn't actually have to control the CD or play any music. Just have the program bring up a window with the appropriate controls, and have each clickable part of the interface respond by printing out a little message.

For some of the buttons in your interface, you may want to use icons instead of text labels. Button widgets accept an option called image that can be used to put an image on the button. The value for the image option should be a BitmapImage object. The constructor for BitmapImage objects accepts an argument named file where you can give the name of an image file to load. The image file must be in XBM format.

Some graphics editors can save files in the XBM format, or if you are patient you can create an XBM file yourself, since it is really a text file. (Here is a good specification of the XBM format.)

So, if the file arrow.xbm contained the following text:

#define arrow_width 16
#define arrow_height 16
static char arrow_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x3c,0x00,0xfc,0x00,0xfc,0x03,0xfc,
 0x0f,0xfc,0x3f,0xfc,0x0f,0xfc,0x03,0xfc,0x00,0x3c,0x00,0x0c,0x00,0x00,0x00,
 0x00,0x00};

Then this would create a button with a "play" arrow on it:

import Tkinter

button = Tkinter.Button()
playarrow = Tkinter.BitmapImage(file='arrow.xbm')
button['image'] = playarrow
button.pack()

The result looks like this:

Again, you only have to deal with all this XBM stuff if you want to put icons on your buttons.

Zwei

Have a look at the Tic-Tac-Toe program. Modify it so that it keeps a scoreboard in a separate window, showing how many games the user has won and how many games the computer has won. Also, provide the option for the user to start a game either as X or as O.


Log in to submit this assignment.
This assignment is due on Monday 31 March at 6 pm. You get a bonus if the assignment is submitted at least 24 hours early.