C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tkinter messageboxThe messagebox module is used to display the message boxes in the python applications. There are the various functions which are used to display the relevant messages depending upon the application requirements. The syntax to use the messagebox is given below. Syntaxmessagebox.function_name(title, message [, options]) Parameters
The two options that can be used are default and parent. 1. default The default option is used to mention the types of the default button, i.e. ABORT, RETRY, or IGNORE in the message box. 2. parent The parent option specifies the parent window on top of which, the message box is to be displayed. There is one of the following functions used to show the appropriate message boxes. All the functions are used with the same syntax but have the specific functionalities. 1. showinfo()The showinfo() messagebox is used where we need to show some relevant information to the user. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.showinfo("information","Information") top.mainloop() Output: 2. showwarning()This method is used to display the warning to the user. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.showwarning("warning","Warning") top.mainloop() Output: 3. showerror()This method is used to display the error message to the user. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.showerror("error","Error") top.mainloop() Output: 4. askquestion()This method is used to ask some question to the user which can be answered in yes or no. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.askquestion("Confirm","Are you sure?") top.mainloop() Output: 5. askokcancel()This method is used to confirm the user's action regarding some application activity. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.askokcancel("Redirect","Redirecting you to www.TheDeveloperBlog.com") top.mainloop() Output: 6. askyesno()This method is used to ask the user about some action to which, the user can answer in yes or no. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.askyesno("Application","Got It?") top.mainloop() Output: 7. askretrycancel()This method is used to ask the user about doing a particular task again or not. Consider the following example. Example# !/usr/bin/python3 from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") messagebox.askretrycancel("Application","try again?") top.mainloop() Output:
Next TopicWeb Blocker Introduction
|