Python 3 GUI Program tkinter Radio Buttons

By | March 24, 2020

Topic: Python 3 GUI Program tkinter Radio Buttons

Python 3 GUI Program tkinter Radio Buttons

Python 3 GUI Program tkinter Radio Buttons

from tkinter import *  
  
def selection():  
   choice = "You selected the option " + str(radio.get())
   if   radio.get()== 1:
           choice = choice + " - Python"
   elif  radio.get()== 2:
           choice = choice + " - Java"
   elif  radio.get()== 3:
           choice = choice + " - C++"
   label.config(text = choice)  
  
window = Tk()  
window.geometry("400x200")  
radio = IntVar()  
lbl = Label(text = "Favourite programming language:", bg='lightgreen',
            font=('verdana',12))  
lbl.pack()  
radio1 = Radiobutton(window, text="Python", variable=radio, value=1,  
                  command=selection)  
radio1.pack( anchor = W )  
  
radio2 = Radiobutton(window, text="Java", variable=radio, value=2,  
                  command=selection)  
radio2.pack( anchor = W )  
  
radio3 = Radiobutton(window, text="C++", variable=radio, value=3,  
                  command=selection)  
radio3.pack( anchor = W)  
  
label = Label(window, text='', bg='green', fg='white', font=('verdana',10))  
label.pack()  
window.mainloop()  

2 thoughts on “Python 3 GUI Program tkinter Radio Buttons

  1. Pingback: Multiplication Table Python GUI Program | EasyCodeBook.com

  2. Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *