How can I dynamically create ttk widgets depending on the value entered in a ttk.entry box?
<p>I am trying to make a GUI where as soon as the user inputs an integer into a <code>ttk.entry</code> field, that many checkbuttons need to appear below it. For example, if they put "5" into the entry widget, 5 check buttons need to appear below the entry field.</p>

<p>Edit:</p>

<p>What I ended up using:</p>

<pre><code>self.number_of_stages = tk.IntVar()
self.check_box_dict={}
self.num_of_stages={}
self.stagetempvar={}
self.equipment_widgets={}


def centrifugal_compressor_widgets(self):
    self.equipment_widgets.clear()
    self.equipment_widgets["NumOfStagesLabelCentComp"]=tk.Label(self.parent, text="Number of Stages:", bg="white")
    self.equipment_widgets["NumOfStagesLabelCentComp"].place(relx=0.5, y=260, anchor="center")

    self.equipment_widgets["NumOfStagesEntryCentComp"]=ttk.Entry(self.parent, textvariable=self.number_of_stages)
    self.equipment_widgets["NumOfStagesEntryCentComp"].place(relx=0.5, y=290, anchor="center")

def OnTraceCentComp(self, varname, elementname, mode):
    for key in self.check_box_dict:
        self.check_box_dict[key].destroy()
    try:
        if self.number_of_stages.get() &lt;=15 :
            i=1
            self.stagetempvar.clear()
            while i &lt;= self.number_of_stages.get():
                self.stagetempvar[i]=tk.StringVar()
                self.stagetempvar[i].set("Closed")
                self.check_box_dict[i]=ttk.Checkbutton(self.parent, text=i, offvalue="Closed", onvalue="Open",variable=self.stagetempvar[i])
                self.check_box_dict[i].place(relx=(i*(1/(self.number_of_stages.get()+1))), y=360, anchor="center")
                i+=1
    except:
        pass
</code></pre>

<p>take a look at the below and let me know what you think...</p>

<p>A very ugly, super basic example:</p>

<pre><code>from Tkinter import *

root = Tk()
root.geometry('200x200')
root.grid_rowconfigure(0, weight = 1)
root.grid_columnconfigure(0, weight = 1)

win1 = Frame(root, bg= 'blue')
win1.grid(row=0, column=0, sticky='news')


number = IntVar()
entry = Entry(win1, textvariable = number)
entry.pack()
confirm = Button(win1, text = 'Press to create widgets...', command = lambda:create_widgets(number.get()))
confirm.pack()

def create_widgets(number):
    for n in range(0,number):
        Checkbutton(win1, text = 'Checkbutton number : %s' % n).pack()

root.mainloop()
</code></pre>

python python-2.7 tkinter