Trying to create sudoku game using tkinter grid, got problem with the GUI grid
The problem is
blocks = [[None] * 3] * 3
it doesn't create 3 unique sublists but it creates 3 reference to the same list.
It should be
blocks = [[None for x in range(3)] for x in range(3)]
I would also use
btn_cells = [[None for x in range(9)] for x in range(9)]
Frankly, I would write it in different way - using apppend()
blocks = []
for r in range(3): # `r` like `row`
row = []
for c in range(3): # `c` like `column`
frame = tk.Frame(puzzle, bd=1, highlightbackground='light blue',
highlightcolor='light blue', highlightthickness=1)
frame.grid(row=r, column=c, sticky='nsew')
row.append(frame)
blocks.append(row)
Generating sudoku puzzle in matrix than drawing GUI
When you generate the board, you only return the first row instead of the entire board.
Make this change in your code:
def generate_board():
.........
# for line in board: return line # remove this line
return board # return full board
Styling a sudoku grid
The following is a slight modification of an example in the table
element section in HTML5 CR, illustrating the use of colgroup
for grouping columns and tbody
for grouping rows. This grouping lets you set different borders around the groups than otherwise around cells.
<style>
table { border-collapse: collapse; font-family: Calibri, sans-serif; }
colgroup, tbody { border: solid medium; }
td { border: solid thin; height: 1.4em; width: 1.4em; text-align: center; padding: 0; }
</style>
<table>
<caption>Sudoku of the day</caption>
<colgroup><col><col><col></colgroup>
<colgroup><col><col><col></colgroup>
<colgroup><col><col><col></colgroup>
<tbody>
<tr> <td>1 <td> <td>3 <td>6 <td> <td>4 <td>7 <td> <td>9
<tr> <td> <td>2 <td> <td> <td>9 <td> <td> <td>1 <td>
<tr> <td>7 <td> <td> <td> <td> <td> <td> <td> <td>6
<tbody>
<tr> <td>2 <td> <td>4 <td> <td>3 <td> <td>9 <td> <td>8
<tr> <td> <td> <td> <td> <td> <td> <td> <td> <td>
<tr> <td>5 <td> <td> <td>9 <td> <td>7 <td> <td> <td>1
<tbody>
<tr> <td>6 <td> <td> <td> <td>5 <td> <td> <td> <td>2
<tr> <td> <td> <td> <td> <td>7 <td> <td> <td> <td>
<tr> <td>9 <td> <td> <td>8 <td> <td>2 <td> <td> <td>5
</table>
Related Topics
Firefox 4 Not Rendering A:Visited::Before (Except Color)
Less Class Name String Interpolation Not Working
Combining CSS Pseudo-Elements, ":After" the ":Last-Child"
CSS - CSS3 Pixelate Dot Background
Font and Line Spacing in Different Browsers
Bootstrap 4.0 - Two Navbars That Collapse into One Toggle
Jquery UI Tooltip Custom Class on Page Load
Print Contents of a Modal Popup
Font Awesome 5 Pseudo-Class Not Working with My Kit
How to Select an Element with 2 Classes
Keeping A: Active Until Another Link Is Clicked
Sass --Watch with Automatic Minify
Font Face Isn't Working in Iis 8.0
Rotating CSS Cube on Fixed Axes
The Old Center a Image in a Div Issue ( Image Size Variable - Div Size Fixed )