'Drop-down menu is not showing in Combobox tkinter

I'm trying to make a drop-down menu for tkinter gui (Combobox). The code has no errors, but drop-down menu is not working. I'm using PyCharm, macOS. Please see the code below.

import tkinter as tk
from tkinter import ttk
import sys


class cpuMon(tk.Tk):

    def __init__(self):
        tk.Tk.__init__(self)
        self.geometry('400x400+1+1')
        self.attributes('-alpha', 1)
        self.attributes('-topmost', True)
        self.resizable(False, False)
        self.title('CPU Monitor')

        self.set_ui()

    def set_ui(self):
        exitButton = ttk.Button(self, text='Exit', command=self.exit_app)
        exitButton.pack(fill=tk.X)

        self.bar2 = ttk.LabelFrame(self, text='Manual')
        self.bar2.pack(fill=tk.X)

        ttk.Button(self.bar2, text='Move').pack(side=tk.LEFT)
        ttk.Button(self.bar2, text='>>>').pack(side=tk.LEFT)

        self.combo_win = ttk.Combobox(self.bar2, state='readonly', values=["hide", "don't hide", "min"])
        self.combo_win.pack(side=tk.LEFT)


Solution 1:[1]

So, I had to fix a few things to get this to run (i.e., instantiating app = cpuMon() and calling app.mainloop(). Likewise, I replaced self.exit_app with self.quit since you didn't share the code for exit_app().

But without modifying the code otherwise, I see that the combo_win dropdown is populated with the values given.

If the issue you're having is that combo_win is empty by default (which it is, using the code given), you'll need to set the initial selection with:

self.combo_win.current(0)  # set the combo box to 'hide' by default

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JRiggles