May-25-2021, 04:43 PM
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()
