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 Functions:
messagebox.name_of_function(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 function 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 function 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() function of size “100X100”.
4. Applying other widget and function
In our example we create a method named Submit and call the askquestion() and Creating Button and setting it by Pack() function
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.function_name(Title, Message, icon='error')
messagebox.function_name(Title, Message, icon='info')
messagebox.function_name(Title, Message, icon='question')
messagebox.function_name(Title, Message, icon='warning')
- Python - Tkinter Choose color Dialog
- Python | askopenfile() function in Tkinter
- Python | Binding function in Tkinter
- Python | Simple GUI calculator using Tkinter
- Python | Add style to tkinter button
- Python | Tkinter ttk.Checkbutton and comparison with simple Checkbutton
- Python Tkinter | Create LabelFrame and add widgets to it
- Python | asksaveasfile() function in Tkinter
- Python | geometry method in Tkinter
- Python | after method in Tkinter
- Python | Menu widget in Tkinter
- Python | Create a digital clock using Tkinter
- resizable() method in Tkinter | Python
- minsize() method in Tkinter | Python
- maxsize() method in Tkinter | Python
- Python | Loan calculator using Tkinter
- Python | Add image on a Tkinter button
- destroy() method in Tkinter | Python
- Getting screen's height and width using Tkinter | Python
- Progressbar widget in Tkinter | Python
Improved By : Akanksha_Rai