from __future__ import division from Tkinter import * colors = ["black", "red", "yellow", "#78A0B4", "#245478", "#181860", "#000050"] colorindex = 0 color = colors[colorindex] def getcolor(): return color def incrcolor(obj): def f(): global colorindex, color colorindex = (colorindex + 1) % len(colors) color = colors[colorindex] obj["bg"] = color return f def setcolor(obj): def f(): obj["bg"] = color return f height = 69 # 4+5/16 inch at 1/16 inch/pixel width = 69 nheight = 14 nwidth = 25 class Application(Frame): def createWidgets(self): for i in range(nwidth): for j in range(nheight): b = Button(self, bg = "black") b.config(command = setcolor(b)) b.place(height = height, width = width, x = i * height, y = j * width) b = Button(self, fg = "green", bg = color, text = "Switch color") b.config(command = incrcolor(b)) b.place(height = 50, width = 100, x = 0, y = height * (nheight+1)) b = Button(self, text = "Exit", command = self.quit) b.place(height = 50, width = 50, x = 120, y = height * (nheight+1)) b = Button(self, bg = "bisque2") b.place(height = 40*16, width = 27*16) b = Button(self, bg = "bisque2") b.place(height = 40*16, width = 27*16, x = width * nwidth - 27*16) # Hood (horizontal part) b = Button(self, bg = "gray90") b.place(height = 4.75*16, width = 42*16, x = (width * nwidth - 42*16) / 2, y = (height * nheight - 30*16) - 4.75*16) # Hood (vertical part) b = Button(self, bg = "gray90") b.place(height = (height * nheight - 30*16) - 4.75*16, width = 14 * 16, x = (width * nwidth - 14*16)/2) # Riser b = Button(self, bg = "gray90") b.place(height = 10*16, width = 36*16, x = (width * nwidth - 36*16)/2, y = (height * nheight - 10*16)) def __init__(self, master): Frame.__init__(self, master) master.config(height = height * (nheight+2), width = width * nwidth) self.place(height = height * (nheight+2), width = width * nwidth) self.createWidgets() app = Application(Tk()) app.mainloop()