Q:

Trying to put drop down list on a code using Tkinter

I'm tring to put some drop down list on a graphic interface I'm building. 
I've found the following code for a drop down list, but I'm not able to adapt it to my code.
from Tkinter import *

def print_it(event):
    print var.get()

root = Tk()
var = StringVar()
var.set("a")
OptionMenu(root, var, "a","b","c", command=print_it).pack()
root.mainloop() 

This is my code, it's quite simple what I've done so far. A menu shows up, it asks for how many (n) components does the users want to enter, and it shows n options to entry. The code above shows 'blank' entrys after you put the desired number of components. I want to replace those three blank entrys with three drop down list.
It's marked when I want to put those dropdown lists.
from Tkinter import *
import Image
import ImageTk
import tkFileDialog

class Planificador:
    def __init__(self,master):
        master.title("Planificador")
        self.frameOne = Frame(master)
        self.frameOne.grid(row=0,column=0)

        # Logo
        self.imgLabel = Label(self.frameOne, image = None)
        self.imgLabel.grid(row=0,column=0)
        self.img = ImageTk.PhotoImage(file = "logo.png")
        self.imgLabel["image"] = self.img

        self.botones()

    def botones(self):
        self.piezastext = Label(self.frameOne, text = " number of components ", justify="center")
        self.piezastext.grid(row=1, column=0)
        self.entrypiezas = Entry(self.frameOne,width=5)
        self.entrypiezas.grid(row=2, column=0)
        self.aceptarnumpiezas = Button(self.frameOne,text="Aceptar", command=self.aceptar_piezas,width=8)
        self.aceptarnumpiezas.grid(row=6, column=0)

    def aceptar_piezas(self):
        num_piezas = self.entrypiezas.get()
        print num_piezas

        self.piezastext.grid_remove()
        self.entrypiezas.grid_remove()
        self.aceptarnumpiezas.grid_remove()

        n = 1;
        while n <= int(num_piezas):
            self.textopieza = Label(self.frameOne, text = "Pieza", justify="left")
            self.textopieza.grid(row=n, column=0)

                    // INSTEAD THESE 'n' BLANK ENTRYS, I WANT TO PUT 'n' DROP DOWN LISTS
            self.entrypiezas = Entry(self.frameOne,width=5)
            self.entrypiezas.grid(row=n, column=1)

            self.aceptarpiezas = Button(self.frameOne,text="Aceptar",width=8)
            self.aceptarpiezas.grid(row=int(num_piezas)+1, column=0)

            n += 1

# Main
if __name__ == "__main__":
    # create interfacE
    root = Tk()
    movieApp = Planificador(root)
    root.mainloop()

So I want to know how can I put that drop down list on a given frame, frameOnein my case, instead of a full window. Thanks in advance.

A:

I modified your aceptar_piezas function to do what I think you want:
def aceptar_piezas(self):
    num_piezas = self.entrypiezas.get()
    print num_piezas

    self.piezastext.grid_remove()
    self.entrypiezas.grid_remove()
    self.aceptarnumpiezas.grid_remove()
    # Create a list of tuples to hold the dynamically created Optionmenus
    # The first item in the tuple is the menu, the second is its variable
    self.optionmenus = list()
    n = 1
    while n <= int(num_piezas):
        self.textopieza = Label(self.frameOne, text = "Pieza", justify="left")
        self.textopieza.grid(row=n, column=0)

        # Variable for the Optionmenu
        var = StringVar()
        # The menu
        menu = OptionMenu(self.frameOne, var, "a","b","c")
        menu.grid(row=n, column=1)
        # Set the variable to "a" as default
        var.set("a")
        # Add the menu to the list of Optionmenus
        self.optionmenus.append((menu, var))

        n += 1
    def clicked():
        """This function was made just to demonstrate.  It is hooked up to the button"""
        for optionmenu in self.optionmenus:
            print optionmenu[1].get()
        print self.optionmenus
    # This button doesn't need to be in the while loop
    self.aceptarpiezas = Button(self.frameOne, text="Aceptar", command=clicked, width=8)
    self.aceptarpiezas.grid(row=int(num_piezas)+1, column=0)

The tuples in the list are in the order that the Optionmenus were created.  So, the first tuple contains the data for the first Optionmenu, the second for the second, and so forth.

