top of page

Python Tkinter

Public·1 member

Tkinter Tutorial 6: Standard Dialogs

This is another important part of GUI programming: displaying dialogs and message boxes. Starting with Tk 4.2, the Tk library provides a set of standard dialogs that can be used to display message boxes.

Python Tkinter – MessageBox Widget is used to display the message boxes in the python applications. This module is used to display a message using provides a number of functions.


Message Boxes

The tkMessageBox module provides an interface to the message dialogs:


Syntax:

messagebox.Function_Name(title, message [, options]) 

Here:

  • Function_Name: This parameter is used to represents an appropriate message box function.

  • title: This parameter is a string which is shown as a title of a message box.

  • message: This parameter is the string to be displayed as a message on the message box.

  • options: There are two options that can be used are:

    1. default: This option is used to specify the default button like ABORT, RETRY, or IGNORE in the message box.

    2. parent: This option is used to specify the window on top of which the message box is to be displayed.


Function_Name: There are functions or methods available in the messagebox widget.

  1. showinfo(): Show some relevant information to the user.

  2. showwarning(): Display the warning to the user.

  3. showerror(): Display the error message to the user.

  4. askquestion(): Ask question and user has to answered in yes or no.

  5. askokcancel(): Confirm the user’s action regarding some application activity.

  6. askyesno(): User can answer in yes or no for some action.

  7. askretrycancel(): Ask the user about doing a particular task again or not.


Now we have learn it using below example:


Example:


info window:


from tkinter import * 
from tkinter import messagebox
  
root = Tk()
root.geometry("300x200")
  
w = Label(root, text ='GeeksForGeeks', font = "50") 
w.pack()
  
messagebox.showinfo("showinfo", "Information")

root.mainloop() 

Output:









Warning window:

from tkinter import * 
from tkinter import messagebox
  
root = Tk()
root.geometry("300x200")
  
w = Label(root, text ='GeeksForGeeks', font = "50") 
w.pack()
  
messagebox.showinfo("showinfo", "Information")
  
messagebox.showwarning("showwarning", "Warning")
  
root.mainloop()

Output:











As like you can create other message dialogs


messagebox.showerror("showerror", "Error")
  
messagebox.askquestion("askquestion", "Are you sure?")
  
messagebox.askokcancel("askokcancel", "Want to continue?")
  
messagebox.askyesno("askyesno", "Find the value?")

messagebox.askretrycancel("askretrycancel", "Try again?")


16 Views
bottom of page