Created
April 12, 2022 01:33
-
-
Save mrprogrammer2938/894cb80f7828d09199405a259fbdd8e2 to your computer and use it in GitHub Desktop.
Tkinter Tutorial - Comboxbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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