Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from invaders import *
- class App(object):
- def __init__(self):
- self.root = Tk()
- self.root.title("Scalable Graphics Test")
- self.root.minsize(144, 8)
- self.root.aspect(144, 8, 144, 8)
- self.cv = Canvas(self.root, width=576, height=32, bg="white", highlightthickness=0)
- self.cv.pack(expand=True, fill=BOTH)
- self.quantity = 12
- self.root.bind("<Configure>", self.redraw)
- self.root.bind("q", lambda e: e.widget.quit())
- self.root.mainloop()
- def draw_invader(self, x, y, width, height):
- for coord in Invaders.front_invader:
- cx = x + coord[1] * width
- cy = y + coord[0] * height
- self.cv.create_rectangle(cx, cy, cx + width, cy + height, fill="#8888ff", width="0")
- self.cv.pack()
- def redraw(self, event):
- self.cv.delete(ALL)
- w, h = event.width, event.height
- slot_width = w / self.quantity
- slot_height = h
- invader_width = floor(slot_width / 12)
- invader_height = floor(slot_height / 8)
- for i in range(0, self.quantity):
- x = i * slot_width
- self.draw_invader(x, 0, invader_width, invader_height)
- App()
Add Comment
Please, Sign In to add comment