Tkinter RadioButton

Tkinter Radiobutton Widget Is Also Known As Multiple-Choice Button Or Option Button. Radiobutton Permits The User To Pick Only One Option From a List. Text Or Images Can Be Used In Radio Buttons. Only a Single Font Can Be Displayed By The Button.

The IntVar() Function Can Be Used To Create a Control Variable. StringVar() Is a Variable That Can Be Used To Return a String Value.

Below You Can See Simple Radio Button-----

Go To Your Pycharm IDE and Write This code Same As 

from tkinter import *
root = Tk()
root.title("Simple Radio Button")
root.geometry("310x350+650+86")
rbtn1= Radiobutton(root, text="Male", font=("helvetica", 15, "bold"), value=1)
rbtn1.pack()
rbtn2= Radiobutton(root, text="Female",font=("helvetica", 15, "bold"), value=2)
rbtn2.pack()
rbtn3= Radiobutton(root, text="Other",font=("helvetica", 15, "bold"), value=3)
rbtn3.pack()
rbtn4= Radiobutton(root, text="OnlyMale",font=("helvetica", 15, "bold"), value=4)
rbtn4.pack()
rbtn5= Radiobutton(root, text="OnlyFemale",font=("helvetica", 15, "bold"), value=5)
rbtn5.pack()
root.mainloop()

Now Press Shift+F10 And See Your Result As Below


If You Want To Select Only Male Option You Can Use This Code rbtn1.select()

Now I can Write the Full Program.............

from tkinter import *
root = Tk()
root.title("Simple Radio Button")
root.geometry("610x350+650+86")
rbtn1= Radiobutton(root, text="Male", font=("helvetica", 15, "bold"),value=1)
rbtn1.select() #Only Male Button Is Selected
rbtn1.pack()
rbtn2= Radiobutton(root, text="Female",font=("helvetica", 15, "bold"),value=2)
rbtn2.pack()
rbtn3= Radiobutton(root, text="Other",font=("helvetica", 15, "bold"),value=3)
rbtn3.pack()
rbtn4= Radiobutton(root, text="OnlyMale",font=("helvetica", 15, "bold"),value=4)
rbtn5= Radiobutton(root, text="OnlyFemale",font=("helvetica", 15, "bold"),value=5)
rbtn5.pack()

root.mainloop()


The Output is Shone As Below Only Male Are Selected
















Post a Comment

Previous Post Next Post