view main.py @ 40:94945f11c78d
snake.Snake.fill: tail takes precedence over body & head
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Sun, 19 Dec 2010 22:46:39 +0300 |
parents |
af9337dd3cf1 |
children |
21a5779088e6 |
line source
2 import tkFileDialog as tkfd
11 self.root.title("Python Battle")
12 self.canvas = tk.Canvas(self.root, background = "black")
13 self.canvas.pack(side ="top", fill="both", expand="yes")
14 buttons = tk.Frame(self.root)
15 buttons.pack(side ="bottom", fill="both", expand="yes")
16 self.buttons_pack(buttons)
18 self.engine = engine.Engine(self.canvas)
21 def buttons_pack(self, frame):
22 load_1 = tk.Button(frame, text="Load 1", command=lambda: self.load(1))
23 load_1.pack(side="left", fill="both", expand = "yes")
24 load_2 = tk.Button(frame, text="Load 2", command=lambda: self.load(2))
25 load_2.pack(side="left", fill="both", expand = "yes")
26 run_b = tk.Button(frame, text="Run", command=lambda: self.run())
27 run_b.pack(side="left", fill="both", expand = "yes")
28 load_3 = tk.Button(frame, text="Load 3", command=lambda: self.load(3))
29 load_3.pack(side="right", fill="both", expand = "yes")
30 load_4 = tk.Button(frame, text="Load 4", command=lambda: self.load(4))
31 load_4.pack(side="right", fill="both", expand = "yes")
32 step_b = tk.Button(frame, text="Step", command=lambda: self.step())
33 step_b.pack(side="right", fill="both", expand = "yes")
36 def load (self, snake_number):
37 if self.step_id >= 200:
40 elif self.step_id == 0:
41 file_name = tkfd.askopenfilename(title="Open file")
42 snake = self.engine.create_snake(snake_number)
50 self.step_id = self.step_id+1
52 self.after_id = self.canvas.after(300, self.run())
53 if self.step_id == 200:
54 self.canvas.after_cancel(self.after_id)
59 if self.step_id <= 200:
60 if self.after_id != None:
61 self.canvas.after_cancel(self.after_id)
63 self.step_id = self.step_id+1
73 end_label = tk.Label(root, text="End")
79 snake_batle.root.mainloop()