view main.py @ 96:3619305694ad
Actually fixed buttons resizing. Fixed code separation for buttons drawing.
author |
Danya Alexeyevsky <me.dendik@gmail.com> |
date |
Mon, 20 Dec 2010 02:26:35 +0300 |
parents |
dcd9d23e77d7 |
children |
4436cf8ba30c |
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 self.buttons_pack(self.root).pack(side ="bottom", fill="both", expand="no")
16 self.engine = engine.Engine(self.canvas)
19 def buttons_pack(self, root):
20 buttons = tk.Frame(root)
21 load_1 = tk.Button(buttons, text="Load 1", command=lambda: self.load(1))
22 load_1.pack(side="left", fill="both", expand = "yes")
23 load_2 = tk.Button(buttons, text="Load 2", command=lambda: self.load(2))
24 load_2.pack(side="left", fill="both", expand = "yes")
25 run_b = tk.Button(buttons, text="Run", command=lambda: self.run())
26 run_b.pack(side="left", fill="both", expand = "yes")
27 load_3 = tk.Button(buttons, text="Load 3", command=lambda: self.load(3))
28 load_3.pack(side="right", fill="both", expand = "yes")
29 load_4 = tk.Button(buttons, text="Load 4", command=lambda: self.load(4))
30 load_4.pack(side="right", fill="both", expand = "yes")
31 step_b = tk.Button(buttons, text="Step", command=lambda: self.step())
32 step_b.pack(side="right", fill="both", expand = "yes")
35 def load (self, snake_number):
36 if self.step_id >= 200:
39 elif self.step_id == 0:
40 file_name = tkfd.askopenfilename(title="Open file")
41 snake = self.engine.create_snake(snake_number)
42 snake.load(open(file_name, "r"))
50 self.step_id = self.step_id+1
52 self.after_id = self.canvas.after(300, self.run())
53 if self.step_id == 200:
57 for snake in self.engine.snakes:
59 dead_snakes=dead_snakes+1
66 if self.step_id <= 200:
67 if self.after_id != None:
68 self.canvas.after_cancel(self.after_id)
70 self.step_id = self.step_id+1
79 if self.after_id != None:
80 self.canvas.after_cancel(self.after_id)
83 end_label = tk.Label(root, text="End")
88 if __name__ == "__main__":
90 snake_batle.root.mainloop()