Python Forum
Tkinter reduce OptionMenu height - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Tkinter reduce OptionMenu height (/thread-33767.html)



Tkinter reduce OptionMenu height - euras - May-25-2021

Hi, is there a way to reduce OptionMenu height? Mine are equal to height=1, but they looks still bigger than the rest of Entry. It does not look very pleasant :/

# pip install tkcalendar
# pip install Pillow

# import tkinter module
import tkinter as tk
from tkinter import * 
from tkinter.ttk import *
from tkcalendar import DateEntry
from PIL import Image, ImageTk

# root window
root = tk.Tk()
root.geometry("350x300")
root.title('Login')
# GUI size, font, text size, title
Font_type = "Verdana"
Font_size = 10
#set window color
main_bg = "#adc2eb"
root['background']= main_bg

# padding for widgets using the grid layout
paddings = {'padx': 5, 'pady': 5}

# configure the grid
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=2)

# this will create a label widget
tk.Label(root, text= "", bg="#00486D").grid(column=0, columnspan=2, row=0, sticky=tk.NSEW)

# Select Country
tk.Label(root, text="Select Country:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=1, sticky=tk.W, **paddings)
Countries = ["", "Denmark", "Finland", "Norway", "Sweden"]
variable = StringVar(root)
variable.set(Countries[0]) # default value
l1 = tk.OptionMenu(root, variable, *Countries)
l1.configure(font=(Font_type, Font_size), borderwidth=1)
l1.grid(column=1, row=1, sticky=tk.EW, **paddings)

# Select Business Area
Areas = ["", "Business DK", "Business FI", "Business NO", "Business SE"]
variable1 = StringVar(root)
variable1.set(Areas[0]) # default value
tk.Label(root, text= "Select Area:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=2, sticky=tk.W, **paddings)
l2 = tk.OptionMenu(root, variable1, *Areas)
l2.configure(font=(Font_type, Font_size), borderwidth=1)
l2.grid(column=1, row=2, sticky=tk.EW, **paddings)

# Select Team
Team = ["AMLU"]
variable2 = StringVar(root)
variable2.set(Team[0]) # default value
tk.Label(root, text= "Select Team:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=3, sticky=tk.W, **paddings)
l3 = tk.OptionMenu(root, variable2, *Team)
l3.configure(font=(Font_type, Font_size), borderwidth=1)
l3.grid(column=1, row=3, sticky=tk.EW, **paddings)

# Select Start Date
tk.Label(root, text= "Start Date:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=4, sticky=tk.W, **paddings)
st_date = DateEntry(root, values="Text", year=2021, state="readonly", date_pattern="yyyy-mm-dd", font=(Font_type, Font_size))
st_date.grid(column=1, row=4, sticky=tk.EW, **paddings)

# Select End Date
tk.Label(root, text= "End Date:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=5, sticky=tk.W, **paddings)
end_date = DateEntry(root, values="Text", year=2021, state="readonly", date_pattern="yyyy-mm-dd", font=(Font_type, Font_size))
end_date.grid(column=1, row=5, sticky=tk.EW, **paddings)

# username
tk.Label(root, text="Username:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=6, sticky=tk.W, **paddings)
username_entry = tk.Entry(root, font=(Font_type, Font_size))
username_entry.grid(column=1, row=6, sticky=tk.EW, **paddings)

# password
tk.Label(root, text="Password:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=7, sticky=tk.W, **paddings)
password_entry = tk.Entry(root,  show="*", font=(Font_type, Font_size))
password_entry.grid(column=1, row=7, sticky=tk.EW, **paddings)

root.attributes('-topmost', True)
root.mainloop()



RE: Tkinter reduce OptionMenu height - deanhystad - May-25-2021

Use Combobox. It looks like Entry. OptionMenu's appearance fits in better with buttons. If you want to stick with OptionMenu try setting pady=0.


RE: Tkinter reduce OptionMenu height - euras - May-25-2021

I changed OptionMenu with Combobox, turned off the mouse roll affect, and now I try to find how to set a background color for those Comboboxes. Now they are white, I want them to make a little bit more darker. The only way to change the color I found is to change the pop-up colors, but not the Combobox itself, which is presented.. Any ideas?
# pip install tkcalendar
# pip install Pillow
 
# import tkinter module
import tkinter as tk
from tkinter import ttk
from tkinter import * 
from tkinter.ttk import *
from tkcalendar import DateEntry
from PIL import Image, ImageTk

# root window
root = tk.Tk()
root.geometry("350x300")
root.title('Login')
# GUI size, font, text size, title
Font_type = "Verdana"
Font_size = 10
#set window color
main_bg = "#adc2eb"
root['background']= main_bg
root.option_add("*TCombobox*Listbox*Foreground", '#3d3d5c')

# padding for widgets using the grid layout
paddings = {'padx': 5, 'pady': 5}
 
# configure the grid
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=2)

# this will create a label widget
tk.Label(root, text= "", bg="#00486D").grid(column=0, columnspan=2, row=0, sticky=tk.NSEW)

# Select Country
tk.Label(root, text="Select Country:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=1, sticky=tk.W, **paddings)
variable = tk.StringVar()
l1 = ttk.Combobox(root, textvariable = variable, font=(Font_type, Font_size), state='readonly')
l1['values'] = ("Denmark", "Finland", "Norway", "Sweden") 
l1.grid(column=1, row=1, sticky=tk.EW, **paddings)
l1.current()
l1.unbind_class("TCombobox", "<MouseWheel>")


# Select Business Area
tk.Label(root, text= "Select Area:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=2, sticky=tk.W, **paddings)
variable1 = tk.StringVar()
l2 = ttk.Combobox(root, textvariable = variable1, font=(Font_type, Font_size), state='readonly')
l2['values'] = ("Business DK", "Business FI", "Business NO", "Business SE") 
l2.grid(column=1, row=2, sticky=tk.EW, **paddings)
l2.current()
l2.unbind_class("TCombobox", "<MouseWheel>")

# Select Team
tk.Label(root, text= "Select Team:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=3, sticky=tk.W, **paddings)
variable2 = tk.StringVar()
l3 = ttk.Combobox(root, textvariable = variable2, font=(Font_type, Font_size), state='readonly')
l3['values'] = ("AMLU") 
l3.grid(column=1, row=3, sticky=tk.EW, **paddings)
l3.current(0)
l3.unbind_class("TCombobox", "<MouseWheel>")

# Select Start Date
tk.Label(root, text= "Start Date:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=4, sticky=tk.W, **paddings)
st_date = DateEntry(root, values="Text", year=2021, state="readonly", date_pattern="yyyy-mm-dd", font=(Font_type, Font_size))
st_date.grid(column=1, row=4, sticky=tk.EW, **paddings)
 
# Select End Date
tk.Label(root, text= "End Date:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=5, sticky=tk.W, **paddings)
end_date = DateEntry(root, values="Text", year=2021, state="readonly", date_pattern="yyyy-mm-dd", font=(Font_type, Font_size))
end_date.grid(column=1, row=5, sticky=tk.EW, **paddings)
 
# username
tk.Label(root, text="Username:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=6, sticky=tk.W, **paddings)
username_entry = tk.Entry(root, font=(Font_type, Font_size))
username_entry.grid(column=1, row=6, sticky=tk.EW, **paddings)
 
# password
tk.Label(root, text="Password:", bg= main_bg, font=(Font_type, Font_size)).grid(column=0, row=7, sticky=tk.W, **paddings)
password_entry = tk.Entry(root,  show="*", font=(Font_type, Font_size))
password_entry.grid(column=1, row=7, sticky=tk.EW, **paddings)
 
root.attributes('-topmost', True)
root.mainloop()