[Tutor] grid manager question

Phil phillor9 at gmail.com
Mon Feb 13 04:42:27 EST 2023


Thank you for reading this.

I've been going around in circles for hours and getting nowhere.

The code below displays a list of circles, one per column. So far so 
good until I add any other widget under the row of circles. If I add a 
widget in column 8 then the circles are unaffected. If I add a widget 
into any other column (not the same row as the circles) then the circles 
move apart over that widget.

How do I prevent this? Adding pady to the widget doesn't seem to help. 
It must have something with the way that list of circles is laid out.

import tkinter as tk
import led3

class App(tk.Tk):
     def __init__(self, num_leds=8):
         tk.Tk.__init__(self)
         self.title("LED Example")

         self.led_list = []

         for i in range(num_leds):
             led = led3.LED(self, size=20, color='red')
             led.grid(row=0, column=i, padx=5, pady=5)
             self.led_list.append(led)

         self.led = led3.LED(self, size=50, color='green')
         #self.led.grid(row=2, column=0, padx=25, pady=25)

         #tk.Button(self, text='Turn On', 
command=self.led.turn_on).grid(row=1, column=1, padx=5, pady=15)
         tk.Button(self, text='Turn On', 
command=self.led_list[1].turn_on).grid(row=3, column=2, padx=5, pady=15)
         #tk.Button(self, text='Turn Off', 
command=self.led.turn_off).grid(row=2, column=1, padx=5, pady=15)

if __name__ == '__main__':
     app = App()
     app.mainloop()

-- 
Regards,
Phil



More information about the Tutor mailing list