[Tutor] Tkinter frame background colour

alan.gauld at yahoo.co.uk alan.gauld at yahoo.co.uk
Tue Dec 14 03:53:34 EST 2021


   You are building a grid so why use the pack manager? it would all be so
   much easier if you use the grid manager.
   For the red lines I'd consider setting the borders of the entry widgets as
   a possibility. But I haven't tried it....
   Alan g
   From my phone
   On 14 Dec 2021 05:43, Phil <phillor9 at gmail.com> wrote:

     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

     _______________________________________________
     Tutor maillist  -  Tutor at python.org
     To unsubscribe or change subscription options:
     https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list