[Tutor] Tkinter frame background colour
Phil
phillor9 at gmail.com
Tue Dec 14 00:43:18 EST 2021
My original GUI worked but it was a bit of a mess so I've spent most of
the day building a new interface to my sudoku solver. However, there is
one problem. I used to have a red line after the third and sixth column
of boxes, the same with the rows. I achieved this by setting the frame's
background to red and placing some padding after the third and sixth
group of cells so that the red background would show through and show a
red line between the 3 x 3 boxes. Otherwise, I'm happy with the result.
import tkinter as tk
class Root(tk.Tk):
def __init__(self):
super().__init__()
self.title('Sudoku Solver')
self.geometry('300x300')
self.frame = tk.Frame()
self.frame.pack(expand=True)
self.frame.bg="red"
self.entry = [None] * 81
for i in range(81):
r, c = divmod(i, 9)
self.entry[i] = tk.Entry(self.frame, width=2,
justify=tk.CENTER, fg="red")
#if i == i % 3:
pad_x = (4, 0)
self.entry[i].grid(row=r, column=c, padx=pad_x)
self.control_frame = tk.Frame()
self.control_frame.pack(side=tk.TOP, pady=5)
self.b_quit = tk.Button(self.control_frame, text='Quit',
command=self.quit)
self.b_quit.pack(side=tk.LEFT)
self.b_solve = tk.Button(self.control_frame, text='Solve',
command=self.solve)
self.b_solve.pack(side=tk.RIGHT)
def quit(self):
self.destroy()
def solve(self):
self.entry[2].insert(0, '9')
print(self.entry[2].get())
if __name__ == '__main__':
root = Root()
root.mainloop()
--
Regards,
Phil
More information about the Tutor
mailing list