-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
57 lines (45 loc) · 1.64 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from tkinter import *
from tkinter import ttk
import config
class Gui:
items = {}
def __init__(self, root):
self.root = root
self.gameFrame = ttk.Frame(self.root,
borderwidth=0,
relief='sunken')
self.gameFrame.grid()
self.scoreFrame = ttk.Frame(self.gameFrame,
borderwidth=0,
relief='sunken',
width=config.BOARD_WIDTH + 6,
height=50)
self.scoreFrame.grid()
self.buildBoard()
def addItem(self, name, coords):
newItem = {name: VisibleObject(self.board, coords)}
self.items.update(newItem)
def buildBoard(self):
self.board = Canvas(self.gameFrame,
borderwidth=1,
relief='sunken',
width=config.BOARD_WIDTH,
height=config.BOARD_HEIGHT)
self.board.grid()
def move(self, name, coords):
try:
self.items[name].move(coords)
except KeyError:
self.addItem(name, coords)
def process(self):
self.root.update_idletasks()
self.root.update()
class VisibleObject:
def __init__(self, board, coords, colour='black'):
self.coords = coords
self.board = board
self.id = self.board.create_rectangle(self.coords,
fill=colour)
def move(self, coords):
self.coords = coords
self.board.coords(self.id, self.coords)