Different messages in Tkinter | Python
Tkinter provides a messagebox class which can be used to show variety of messages so that user can respond according to those messages. Messages like confirmation message, error message, warning message etc.
In order to use this class one must import this class as shown below:
# import all the functions and constants of this class. from tkinter.messagebox import *
Syntax and uses of different functions of this class –
askokcancel(title=None, message=None, **options)
# Ask if operation should proceed; # return true if the answer is ok.askquestion(title=None, message=None, **options)
# Ask a question.askretrycancel(title=None, message=None, **options)
# Ask if operation should be retried; # return true if the answer is yes.askyesno(title=None, message=None, **options)
# Ask a question; return true # if the answer is yes.askyesnocancel(title=None, message=None, **options)
# Ask a question; return true # if the answer is yes, None if cancelled.showerror(title=None, message=None, **options)
# Show an error message.showinfo(title=None, message=None, **options)
# Show an info message.showwarning(title=None, message=None, **options)
# Show a warning message.
Program to demonstrate various messages:
# importing messagebox class from tkinter.messagebox import * # Showing various messaes print (askokcancel( "askokcancel" , "Ok or Cancel" )) print (askquestion( "askquestion" , "Question?" )) print (askretrycancel( "askretrycancel" , "Retry or Cancel" )) print (askyesno( "askyesno" , "Yes or No" )) print (askyesnocancel( "askyesnocancel" , "Yes or No or Cancel" )) print (showerror( "showerror" , "Error" )) print (showinfo( "showinfo" , "Information" )) print (showwarning( "showwarning" , "Warning" )) # print statement is used so that we can # print the returned value by the function |
Output:
Note: Note that in above program we don not have to import Tkinter module only messagebox molude/class is sufficient because definitions of these functions is in messagebox class.
Recommended Posts:
- Python GUI - tkinter
- Python | after method in Tkinter
- RadioButton in Tkinter | Python
- minsize() method in Tkinter | Python
- maxsize() method in Tkinter | Python
- Python | Simple GUI calculator using Tkinter
- Python | Loan calculator using Tkinter
- Python | Add image on a Tkinter button
- Python | askopenfile() function in Tkinter
- Python | winfo_ismapped() and winfo_exist() in Tkinter
- Python | Binding function in Tkinter
- Collapsible Pane in Tkinter | Python
- iconphoto() method in Tkinter | Python
- Python | PanedWindow Widget in Tkinter
- destroy() method in Tkinter | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.