Tkinter

tkMessageBox Tkinter | Python 3

In this tutorial, we are going to see how to use tkMessageBox in Tkinter. The tkMessageBox widget allows to show the message boxes in your applications. This widget gives us some functions that you can use to display a message. For example showerror, askokcancel, showwarning, showinfo, askquestion, etc…


 
 

Syntax:

Here is the syntax to create this widget:

tkMessageBox.FunctionName(title, message [, options])

 

Parameters:
  • FunctionName : This is the name of the message box function.
  • title : This is the text to display in the title bar of the message box.
  • message : This is the text to be displayed as a message.
  • options : Options are alternative choices you can use to customize a standard message box. Some of the options you can use are default and parent. The default option is used to specify the default button in the message box, such as ABORT, RETRY or IGNORE.

 
You can use any of the following functions with the dialog box:

  • showinfo()
  • showwarning()
  • showerror()
  • askquestion()
  • askokcancel()
  • askyesno()
  • askretrycancel()

 

 

Example:
from tkinter import *
from tkinter import messagebox

gui = Tk()
def msg():
   messagebox.showinfo("Info", "Welcome to StackHowTo!")

btn = Button(gui, text = "Click here!", command = msg)
btn.pack()

gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *