Guest User

Untitled

a guest
Aug 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. from Tkinter import *
  2. from invaders import *
  3.  
  4. class App(object):
  5. def __init__(self):
  6. self.root = Tk()
  7. self.root.title("Scalable Graphics Test")
  8. self.root.minsize(144, 8)
  9. self.root.aspect(144, 8, 144, 8)
  10. self.cv = Canvas(self.root, width=576, height=32, bg="white", highlightthickness=0)
  11. self.cv.pack(expand=True, fill=BOTH)
  12. self.quantity = 12
  13.  
  14. self.root.bind("<Configure>", self.redraw)
  15. self.root.bind("q", lambda e: e.widget.quit())
  16. self.root.mainloop()
  17.  
  18. def draw_invader(self, x, y, width, height):
  19. for coord in Invaders.front_invader:
  20. cx = x + coord[1] * width
  21. cy = y + coord[0] * height
  22. self.cv.create_rectangle(cx, cy, cx + width, cy + height, fill="#8888ff", width="0")
  23. self.cv.pack()
  24.  
  25. def redraw(self, event):
  26. self.cv.delete(ALL)
  27. w, h = event.width, event.height
  28. slot_width = w / self.quantity
  29. slot_height = h
  30. invader_width = floor(slot_width / 12)
  31. invader_height = floor(slot_height / 8)
  32. for i in range(0, self.quantity):
  33. x = i * slot_width
  34. self.draw_invader(x, 0, invader_width, invader_height)
  35.  
  36. App()
Add Comment
Please, Sign In to add comment