If you want to populate your GUI with a ready-made list at startup:
from Tkinter import * root = Tk() premadeList = ["foo", "bar", "baz"] for checkBoxName in premadeList: c = Checkbutton(root, text=checkBoxName) c.pack() root.mainloop()
If you want to dynamically populate your GUI with flags at runtime:
import random import string from Tkinter import * root = Tk() def addCheckBox(): checkBoxName = "".join(random.choice(string.letters) for _ in range(10)) c = Checkbutton(root, text=checkBoxName) c.pack() b = Button(root, text="Add a checkbox", command=addCheckBox) b.pack() root.mainloop()
And of course you can do both:
import random import string from Tkinter import * root = Tk() def addCheckBox(): checkBoxName = "".join(random.choice(string.letters) for _ in range(10)) c = Checkbutton(root, text=checkBoxName) c.pack() b = Button(root, text="Add a checkbox", command=addCheckBox) b.pack() premadeList = ["foo", "bar", "baz"] for checkBoxName in premadeList: c = Checkbutton(root, text=checkBoxName) c.pack() root.mainloop()
Kevin source share