Created
April 11, 2022 12:04
-
-
Save mrprogrammer2938/044c94cd04a9f37ea4236fb396694776 to your computer and use it in GitHub Desktop.
Tkinter Tutorial - Radiobutton
This file contains 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 Button,Radiobutton | |
from tkinter.messagebox import * | |
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() | |
for color in Colors: | |
r = Radiobutton ( | |
root, | |
text=color, | |
value=color, | |
variable=st | |
).pack(fill="x",padx=5,pady=5) | |
btn = Button(root,text="Get",command=get_color).pack(fill="x") | |
exit_btn = Button(root,text="Exit",command=root.quit).pack(fill="x") | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment