In Python, There Are Serval Libraries for Graphical User Interface. Tkinter is one of them that is most useful. It is a standard interface. Tkinter is easy to use and provides serval functions for building efficient applications. In Every Application, we need some Message to Display like “Do You Want To Close ” or showing any warning or Something information. For this Tkinter provide library like messagebox. By using the message box library we can show serval Information, Error, Warning, Cancelation ETC in the from of Message-Box. It has Different the message box for a different purpose.
- showinfo() – To display some important information .
- showwarning() – To display some type of Warning.
- showerror() –To display some Error Message.
- askquestion() – To display dilog box that ask with two options YES or NO.
- askokcancel() – To display dilog box that ask with two options OK or CANCEL.
- askretrycancel() – To display dilog box that ask with two options RETRY or CANCEL.
- askyesnocancel() – To display dilog box that ask with three options YES or NO or CANCEL.
Syntax of the Message-Box Fucntions:
messagebox.name_of_fucntion(Title, Message, [, options]);
- name_of_function – Function name that which we want to use .
- Title – Message Box’s Title.
- Message – Message that you want to show in dailog.
- Options –To configure the options .
This fucntion is used to ask the questions to user. that have only two options YES or NO.
Application of this function –
- We can use this to ask the user that User want’s to continue.
- We can use this to ask the user that User wanted to Submit or not.
messagebox.askfunction((Title, Message, [, options]);
1. Importing the Libraries
To use the GUI functionality in python we have to import the libraries . In the first line we are importing tkinter and second line we importing messagebox library
from tkinter import * from tkinter import messagebox
2. Main window instance
We have to create an instance or object for thw window ot TK(); Tk() is fucntion of tkinter that create a window that can be refered from main variable
main = Tk()
3. Set dimenstion
we set the dimention of the window we can set it by various way.in this we are setting is by geometry() fucntion of size “100X100”.
4. Applying other widget and fucntion
In our example we create a method named Submit and call the askquestion() and Creating Button and setting it by Pack() fucntion
def Submit(): messagebox.askquestion("Form", "Do you want to Submit") main.geometry("100x100") B1 = Button(main, text = "Submit", command = Submit) B1.pack()
This method can be used when all the code is ready to execute.It runs the INFINITE Loop used to run the application.A window will open until the close button is pressed.
ICONS that We can use in Options
We can change the icon of the dialog box. The type of icon that we want to use just depends on the application’s need. we have four icons.
messagebox.fucntion_name(Title, Message, icon='error')
messagebox.fucntion_name(Title, Message, icon='info')
messagebox.fucntion_name(Title, Message, icon='question')
messagebox.fucntion_name(Title, Message, icon='warning')
- Python - Tkinter Choose color Dialog
- PyQt5 Input Dialog | Python
- Raise a File Download Dialog Box in Python
- Python GUI - tkinter
- Python Tkinter - SpinBox
- Python-Tkinter Scrollbar
- Python Tkinter Tutorial
- RadioButton in Tkinter | Python
- Python Tkinter - Message
- Python: Age Calculator using Tkinter
- Python Tkinter - Label
- Different messages in Tkinter | Python
- Python | GUI Calendar using Tkinter
- Python | after method in Tkinter
- GST Rate Finder GUI using Python-Tkinter
- Python | winfo_ismapped() and winfo_exist() in Tkinter
- Python | Simple GUI calculator using Tkinter
- Python Tkinter - Menubutton Widget
- Python Tkinter - ListBox Widget
- Create a Yes/No Message Box in Python using tkinter
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.