gui.py 1.82 KB
Newer Older
nrossol's avatar
nrossol committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#GUI for sudoku solver by Nathan Rossol, Computer Science sophomore at the University of Michigan
from sudokuSolverPython import solveSudoku
import pygame
import os

grid = [ [ 3, 2, 1, 0, 5, 0, 9, 4, 7 ],
        [7, 8, 0, 0, 1, 0, 0, 6, 5],
        [0, 0, 6, 7, 0, 4, 1, 0, 0],
        [5, 4, 9, 0, 0, 0, 7, 8 ,6],
        [0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 9, 0, 6, 0, 0, 0],
        [1, 0, 5, 0, 6, 0, 4, 0, 2],
        [0 ,3 ,0, 2, 0, 7, 0, 5, 0],
        [2, 0, 7, 0, 4, 0, 8, 0, 3] ]

#Basic Colors:
BLACK = (0,0,0)
WHITE = (255,255,255)

20
21
#Initialize Pygame and variables::
pygame.init()
nrossol's avatar
nrossol committed
22
pygame.display.init()
23
24
25
26
screen_width = 490
screen_height = 490
buttonArea = 100 #height of area where buttons will be below the grid
box_size = 50
nrossol's avatar
nrossol committed
27
margin = 5
28
29
30
font = pygame.font.SysFont("Comic Sans MS",30)
screen = pygame.display.set_mode([screen_width,screen_height+buttonArea])
pygame.display.set_caption("Sudoku")
nrossol's avatar
nrossol committed
31
32
33
34
35
36
37
38
clock = pygame.time.Clock()

#Main Loop:
done = False
while not done:
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        
        screen.fill(BLACK)

        #draw grid:
        for i in range(0,screen_width,box_size+margin):
                for j in range(0,screen_height,box_size+margin):
                        pygame.draw.rect(screen, WHITE, (i,j,box_size,box_size), 0)
        pygame.draw.rect(screen, WHITE, (0,495,490,100), 0)

        #fill in grid:
        for i in range(0,9):
                for j in range(0,9):
                        number_surface = font.render(str(grid[i][j]), False, (0,0,0))
                        screen.blit(number_surface, (7 + i*(box_size + margin), 7 + j*(box_size + margin)))

        #update display
        pygame.display.update()

        #make screen update 60 fps
        clock.tick(60)

pygame.quit()
nrossol's avatar
nrossol committed
61
62