0

Im presently working on a 'miniature' Conways Game of Life. The input figure is built using Tkinter checkboxes arranged in a grid. Each checkbox has an IntVar variable attached to it. Right now the program is functional, but I want to expand the input grid from 10 x 10 to 100 x 100 without having to manually type var1... all the way up to var1000. In order to do so I figured I need to create and store in a list each var. The creating part works but I can`t append them to a list. The code which is in need of attention is:

from tkinter import *
import tkinter as tk
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import sys
master = Tk()

L = []

this = sys.modules[__name__]
for x in range(1,101):
    setattr(this, 'var%s' % x, IntVar())

#L = [] # create an empty list
#for i in range(1,101):
#    L.append(tk.IntVar())# add to list
#for i in range(1,101):
#    L[i].set(i)


L = [var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,
     var11,var12,var13,var14,var15,var16,var17,var18,var19,var20,
     var21,var22,var23,var24,var25,var26,var27,var28,var29,var30,
     var31,var32,var33,var34,var35,var36,var37,var38,var39,var40,
     var41,var42,var43,var44,var45,var46,var47,var48,var49,var50,
     var51,var52,var53,var54,var55,var56,var57,var58,var59,var60,
     var61,var62,var63,var64,var65,var66,var67,var68,var69,var70,
     var71,var72,var73,var74,var75,var76,var77,var78,var79,var80,
     var81,var82,var83,var84,var85,var86,var87,var88,var89,var90,
     var91,var92,var93,var94,var95,var96,var97,var98,var99,var100]

1 Answers1

0

this did it

from tkinter import *
import tkinter as tk
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import sys
master = Tk()

    L = []
    
    this = sys.modules[__name__]
    for x in range(1,101):
        setattr(this, 'var%s' % x, IntVar())
        y = getattr(this, 'var%s' % x)
        L.append(y)

I`m sorry for the messy question I asked earlier. this programm is about 100 lines long and I got confused as to how much of it I needed to share here. Thank you very much, people who spared a thought for it.