Python Forum
Tkinter reduce OptionMenu height
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter reduce OptionMenu height
#1
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()

Attached Files

Thumbnail(s)
   
Reply
#2
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.
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 11,280 Apr-27-2020, 10:48 PM
Last Post: Larz60+
  Tkinter - Need Help setting Height of a TextInputBox itslewis 1 1,557 Mar-22-2020, 02:37 AM
Last Post: deanhystad
  [Tkinter] optionmenu value write a list mdalireza 0 2,304 Nov-11-2019, 01:00 PM
Last Post: mdalireza
  [Tkinter] Retrieve OptionMenu selection? JP_ROMANO 5 23,747 Mar-13-2019, 10:56 AM
Last Post: vsathya
  [Tkinter] Lock Text Widget height Oxylium 3 4,226 Feb-14-2019, 10:13 PM
Last Post: woooee
  Canvas Text Width/Height Anysja 0 5,178 Aug-20-2018, 11:11 PM
Last Post: Anysja
  [Tkinter] [split] need help in optionMenu using tkinter Rakeshkrtiwari_07 0 2,264 Aug-02-2018, 04:16 PM
Last Post: Rakeshkrtiwari_07
  [Tkinter] Tkinter optionmenu child menu position showing 0,0 thatguy14 2 4,655 Jun-15-2018, 10:42 AM
Last Post: thatguy14
  [Tkinter] need help in optionMenu using tkinter Lizard 4 6,803 Nov-07-2017, 03:08 PM
Last Post: Lizard
  [Tkinter] Scroll bar height is not fixed with Text widget MeeranRizvi 2 15,467 Feb-06-2017, 12:24 PM
Last Post: MeeranRizvi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020