简体   繁体   中英

Tkinter OptionMenu not displaying properly

I am trying to create a tkinter GUI with drop down selection menus. The dropdowns are not displaying fully and only show the full bar when something has been selected (see images below).

The option menus are created with code similar to this:

startmonth = StringVar()
p1_PubStartMonth = OptionMenu(DateStartFrame, startmonth, "January", "February", "March", "April",
                                                          "May", "June", "July", "August", "September",
                                                          "October", "November", "December")
p1_PubStartMonth.configure(width=10, bg=_active)
p1_PubStartMonth.grid(row=5, column=1)

Does anyone know what could be causing these widgets to show up this way?

在此处输入图片说明

在此处输入图片说明

I got he error: NameError: name '_active' is not defined and when I deleted the bg=_active from the .configure it came out just fine.

Also; OptionMenu behaves slightly different depending on if you get if from Tkinter or Ttk.

Addition

Since I haven't seen all your code I'll include some code that works for me. If this works for you, then you have something to build upon.

from tkinter import *
import tkinter.ttk as ttk

DateStartFrame = Tk()
startmonth = StringVar()
p1_PubStartMonth = ttk.OptionMenu(DateStartFrame, startmonth,
                              "January", "February", "March", "April",
                              "May", "June", "July", "August", "September",
                              "October", "November", "December")
p1_PubStartMonth.configure(width=10)
p1_PubStartMonth.grid()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM