Home > Enterprise >  Why is the drop-down menu appearing at the top?
Why is the drop-down menu appearing at the top?

Time:12-15

Our OOP final project is to create a library "database". Irrelevant details aside, I want to create a drop-down menu for the genre entry rather than have the user enter them manually (more organized database-wise.) I am using tkinter. Clarification: this frame is in a class of its own so I can pack it onto the main window easily.

# Set the menu initially
self.menu = StringVar()
self.menu.set("Select Genre ...")
# Create a dropdown menu
self.genre_drop = OptionMenu(window, self.menu,
                             "Fantasy", "Science Fiction", "Horror", "Mystery", "Romance", "Nonfiction")

# Packing the widgets in order of appearance
self.notice.pack(pady=15)
self.title_label.pack()
self.title.pack()
self.genre_label.pack()
self.genre_drop.pack()
self.isbn_label.pack()
self.isbn.pack()

Thank you in advance!

screenshot of tkinter window

Even though I packed the drop-down after the label, the drop-down is appearing at the top of the frame, before anything else (haven't attached the entire source code because it's 126 lines, but if you need it I'll add it I guess.) What do I do?

Edit: added the beginning of the class. "window" is passed as an argument from the main and is a simple Tk() window.

class AddBook:

    # This starts once the class is called
    def __init__(self, window):
        # Frame details
        self.add_book = Frame(window, width=400, height=500)

CodePudding user response:

It is almost certainly because you've made the option menu a child of the root window, either intentionally or by accident, but the other widgets are the child of a frame.

  • Related