Topic: Python 3 Radio Buttons GUI Program using tkinter
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()
How this Python GUI program works?
Python 3 Radio Buttons
- Import * from tkinter GUI module.
- Define a selection function
- The selection functions uses if-elif statement to select a block of statements to execute on the basis of the corresponding radio buttion selection
- Create main window
- set size of main window 400 x 200
- Set ttle of the main window
- Create 3 radio buttons.
- Create and Place a label in main window
- Call the mainloop() to display the GUI and start the program.
- The main window of the program will show and wait for any action by the user
- As soon as the user selects a radio button, the corresponding text will be shown on the label widget.
You will also like:
- Python GUI Find Factorial by Recursive Function
- Python GUI Multiplication Table
- Python GUI Area of Triangle
- Python GUI Temperature Conversion Program C To F
- Python GUI Program Temperature Conversion Fahrenheit to Celsius
- Python Pounds to Kilogram Converter GUI tkinter Program
- Python 3 Four Function Calculator Program tkinter GUI
- Python Digital Clock Program using tkinter GUI
- Python Quotes Changer Program tkinter GUI
- Chnage Font Size Spinbox GUI Program Example
- Python 3 tkinter Message Widget Program Examples
- Adding Menus to Python 3 tkinter GUI Programs
Pingback: Multiplication Table Python GUI Program | EasyCodeBook.com
Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com
Pingback: Python 3 tkinter Message Widget Program Examples | EasyCodeBook.com