#!/usr/bin/env python #-*- coding:utf-8 -*- from Tkinter import * import sys class Main: status = {} active = 'blue' def __init__(self): window = Tk() self.ctx = Canvas(window, width=600, height=600) self.ctx.bind('', self.clicked) self.ctx.bind('', self.reset) self.ctx.pack() self.init_game() self.status = self.init_dict(30) for m in self.status: self.status[m] = self.init_dict(30) window.mainloop() def init_game(self): self.ctx.create_line(1, 1, 1, 600) self.ctx.create_line(1, 1, 600, 1) for m in range(30): self.ctx.create_line(m * 20 + 20, 0, m * 20 + 20, 600) self.ctx.create_line(0, m * 20 + 20, 600, m * 20 + 20) def clicked(self, event): #print event.x, event.y ruut_x = event.x / 20 ruut_y = event.y / 20 nurk = (ruut_x * 20, ruut_y * 20,) if not self.status[ruut_x][ruut_y]: if self.active == 'blue': self.ctx.create_oval(nurk[0] + 2, nurk[1] + 2, nurk[0] + 18, nurk[1] + 18, fill='blue') self.active = 'red' self.status[ruut_x][ruut_y] = 'blue' elif self.active == 'red': self.ctx.create_oval(nurk[0] + 2, nurk[1] + 2, nurk[0] + 18, nurk[1] + 18, fill='red') self.active = 'blue' self.status[ruut_x][ruut_y] = 'red' def reset(self, event): self.ctx.delete(ALL) self.init_game() self.status = self.init_dict(30) for m in self.status: self.status[m] = self.init_dict(30) def init_dict(self, pikkus): d = {} for i in range(pikkus): d[i] = None return d if __name__ == '__main__': Main()