In this post we will learn how to use Combo boxes on our Tkinter application. Lets get started,
IN[1]
import tkinter as tk
from tkinter import ttk
try :
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except :
pass
root = tk.Tk()
root.title("Comboboxes")
root.geometry("600x400")
root.resizable(False, False)
selected_day = tk.StringVar()
weekday = ttk.Combobox(root, textvariable = selected_day)
weekday["values"] = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
weekday["state"] = "readonly"
weekday.pack()
def h_e(event):
print("The selected day is :", selected_day.get())
print("The fiday will be set")
selected_day.set("Friday")
print(weekday.current())
weekday.bind("<<ComboboxSelected>>",h_e)
root.mainloop()
OUT[1]
EXPLANATION