-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (58 loc) · 2.48 KB
/
main.py
File metadata and controls
79 lines (58 loc) · 2.48 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import copy
from custom_tkinter.CustomWindow import CustomTk, CustomTopLevel
from custom_tkinter.CustomButton import CustomButton
from custom_tkinter.CustomDropdown import CustomDropdown
from custom_tkinter.CustomLabel import CustomLabel
from custom_tkinter.PopUp import PopUp
from utils.colours import WINDOW_BG
from utils.fonts import FONT
from utils.boards import DEFAULT, BOARDS
from board_interface.Board import Board
from board_interface.BoardView import BoardView
from board_interface.BoardCreate import BoardCreate
# Prompts to visually see solution as it's being solved.
def prompt_to_solve():
if PopUp.question() == PopUp.CONFIRM:
__no_solution(True)
board_view.refresh(board)
else:
__no_solution(False)
board_view.place_known_values(board)
# Displays no solution exists message if none exists.
def __no_solution(is_visual):
if not board.solve(board_view, is_visual):
PopUp.info()
# Window to create custom board to solve.
def custom_board():
top_level = CustomTopLevel("Create Sudoku Board")
board_create = BoardCreate(top_level)
instructions = CustomLabel(top_level, "Fill in the 9x9 grid with digits from 1 to 9", FONT["BUTTON"], WINDOW_BG)
instructions.place(rely=0.015, relwidth=1)
# Button to create custom board.
confirm_btn = CustomButton(top_level, "Confirm", lambda: board_create.confirm(board, board_view))
confirm_btn.place(0.375, 0.25)
# Callback when dropdown is selected, updating the backend and view boards with the chosen preset.
def choose_preset(selected_option):
preset = copy.deepcopy(BOARDS[selected_option])
board.set_bo(preset)
board_view.refresh(board)
if __name__ == "__main__":
root = CustomTk("Sudoku Solver")
# Backend and GUI Boards.
board = Board(copy.deepcopy(BOARDS[DEFAULT]))
board_view = BoardView(root, board)
# Button placements.
__width = 0.2
__solve_x = 0.09
__create_x = 0.715
__dropdown_x = (__solve_x + __create_x) / 2
# Button to prompt how board will be solved.
__solve_btn = CustomButton(root, "Solve", lambda: prompt_to_solve())
__solve_btn.place(__solve_x, __width)
# Select board from provided presets.
__dropdown = CustomDropdown(root, list(BOARDS.keys()), choose_preset)
__dropdown.place(__dropdown_x, __width)
# Button to open custom board window.
__create_board_btn = CustomButton(root, "Create", (lambda: custom_board()))
__create_board_btn.place(__create_x, __width)
root.mainloop()