Creating a function to make checkbutton with information from a list?

Thomas Jansson tjansson60 at gmail.com
Sat May 12 14:04:51 EDT 2007


Dear all

I am writing a program with tkinter where I have to create a lot of
checkbuttons. They should have the same format but should have
different names. My intention is to run the functions and the create
all the buttons with the names from the list.

I now the lines below doesn't work, but this is what I have so far. I
don't really know how call the element in the dict use in the for
loop. I tried to call +'item'+ but this doesn't work.

def create_checkbox(self):
   self.checkbutton = ["LNCOL", "LFORM", "LPOT", "LGRID",  "LERR",
"LCOMP"]
   for item in self.checkbutton:
      self.+'item'+Checkbutton = Chekcbutton(frame, onvalue='t',
offvalue='f', variable=self.+'item'+)
      self.+'item'+Checkbutton.grid()

How should I do this?

Kind regards
Thomas Jansson




More information about the Python-list mailing list