Skip to content

Instantly share code, notes, and snippets.

@mrprogrammer2938
Created April 12, 2022 01:33
Show Gist options
  • Save mrprogrammer2938/894cb80f7828d09199405a259fbdd8e2 to your computer and use it in GitHub Desktop.
Save mrprogrammer2938/894cb80f7828d09199405a259fbdd8e2 to your computer and use it in GitHub Desktop.
Tkinter Tutorial - Comboxbox
from tkinter import *
from tkinter.ttk import Combobox,Button
from tkinter.messagebox import showinfo
root = Tk()
root.title("Window")
root.geometry("400x300+500+80")
root.resizable(0,0)
def get_color():
showinfo(title="Information",message=f"Color: {st.get()}")
l = Label(root,text="Choose Color: ").pack(fill="x",padx=5,pady=5)
Colors = [
"black",
"white",
"blue",
"red",
"green",
"yellow"
]
st = StringVar()
com = Combobox(root,textvariable=st,values=Colors)
com["state"] = "readonly"
com.current(0)
com.pack(padx=5,pady=5)
btn = Button(root,text="Get",command=get_color).pack()
exit_btn = Button(root,text="Exit",command=root.quit).pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment