Create Warning, Information and Error MessageBoxes from Radiobuttons

by Apr 22, 2020Python Tkinter

Introduction

We will create a Graphical User Interface using tkinter on python to display messageboxes from radiobuttons. To learn how to use python, you can check these tutorials. If you know python but want to learn how to use tkinter, you can check these tutorials. If you know tkinter but aren’t familiar with messageboxes, you can check that here.

This is the GUI window with RadioButtons

The code to create warning, information and error messages using radio buttons is given below:

from tkinter import *
from tkinter import messagebox as msg 

root = Tk()
root.title("Messagebox assignment")
root.iconbitmap("IOTEDU.ico")

def clicked():
    if var.get() == 1:
        info = msg.showinfo("Show info messagebox", "This message box is used to show information.")
    elif var.get() == 2:
        warn = msg.showwarning("Show warning messagebox", "This message box is used to show warnings.")
    if var.get() == 3:
        error = msg.showerror("Show error messagebox", "This message box is used to show errors.")


var = IntVar()

Radiobutton(root, variable = var, text = "Information messagebox", value = 1, command = clicked).grid(row = 0, column = 0,  padx = 5, pady = 5, sticky = 'w')
Radiobutton(root, variable = var, text = "Warning messagebox", value = 2, command = clicked).grid(row = 1, column = 0, padx = 5, pady = 5, sticky = 'w')
Radiobutton(root, variable = var, text = "Error messagebox", value = 3, command = clicked).grid(row = 2, column = 0, padx = 5, pady = 5, sticky = 'w')


root.mainloop()


Steps along with explanation

  • To begin with, we will import tkinter and the messagebox module from tkinter.
from tkinter import *
from tkinter import messagebox as msg 
  • Then we will create a root window for out radio buttons.

You can also give a title of your choice.

root = Tk()
root.title("Messagebox assignment")
root.iconbitmap("IOTEDU.ico")
  • We can then go ahead and create three radio buttons, display them on our root window using the grid and apply padding to it.

We can also use a variable and assign it different values when different radio boxes are selected.

var = IntVar()

Radiobutton(root, variable = var, text = "Information messagebox", value = 1, command = clicked).grid(row = 0, column = 0,  padx = 5, pady = 5, sticky = 'w')
Radiobutton(root, variable = var, text = "Warning messagebox", value = 2, command = clicked).grid(row = 1, column = 0, padx = 5, pady = 5, sticky = 'w')
Radiobutton(root, variable = var, text = "Error messagebox", value = 3, command = clicked).grid(row = 2, column = 0, padx = 5, pady = 5, sticky = 'w')
  • Then we create a function “clicked” which displays the messageboxes when the radio buttons are selected.
def clicked():
    if var.get() == 1:
        info = msg.showinfo("Show info messagebox", "This message box is used to show information.")
    elif var.get() == 2:
        warn = msg.showwarning("Show warning messagebox", "This message box is used to show warnings.")
    if var.get() == 3:
        error = msg.showerror("Show error messagebox", "This message box is used to show errors.")

Output

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

Data And Classes in Python Tkinter

Data And Classes in Python Tkinter

In this article, we are going to learn about data and classes in python Tkinter. We will save our GUIdata into Tkinter variables after that we will also start using OOP to extend the existing Tkinter classes to extend the built-in functionality of Tkinter....

Python Tkinter MessageBox-Example

Python Tkinter MessageBox-Example

INTRODUCTION In this article, we will learn “How to interface the radio button and messages with Tkinter”. I recommend you to go through this first similarly if you are new to Tkinter go through this. Here we will design a GUI with a 4 radio button and...

asksaveasfile() function in Python-Tkinter

asksaveasfile() function in Python-Tkinter

In this tutorial, we will be learning how to use the asksaveasfile() in Tkinter and save the file in the system. The asksaveasfile() function comes under the class filedialog. The file dialog module provides functions for creating file/directory selection...

Graphical User Interface with tkinter python

Graphical User Interface with tkinter python

In this article, we will tell about the GUI(graphical user interface) in python using. We should also know about how to import the library and using some widgets in it. Let’s have a quick look at the below contents. Contents IntroductionWhat is Tkinter?Packaging...

Plotting graphs with Matplotlib (Python)

Plotting graphs with Matplotlib (Python)

In this tutorial, you'll learn about matplotlib, the plotting library of Python. You'll also get to learn how do we use it for plotting different types of graphs in Python. What is Matplotlib? Matplotlib is an amazing visualization library in Python for 2D plots of...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....