Creating a prompt dialog box using Tkinter?


Dialog Boxes are handy for informing users to perform certain operations. We are already familiar with the dialog boxes and interacted with them many times. In a particular Tkinter application, we can create any type of dialog boxes, such as Message, User Interaction Dialogs, Single Value Entry Dialogs, File chooser, etc. To create dialog boxes, Tkinter has several built-in packages like a messagebox, simpledialog, filedialog, and colorchooser.

Example

In this example, we will create a message box to inform the user to choose an option.

#Import the tkinter library
from tkinter import *
from tkinter import messagebox
#Create an instance of Tkinter frame
win= Tk()
#Define the geometry of the function
win.geometry("750x250")
answer = messagebox.askyesno("Question","Do you like Python Tkinter?")
#Create a Label
Label(win, text=answer, font= ('Georgia 20 bold')).pack()
win.mainloop()

Output

Running the above code will display a prompt dialog box. Once we choose an option, it will display the Boolean value based on Yes (1) or No (0).

Once we click on Yes or No, it will update the Tkinter window with 1 or 0 values.

Updated on: 21-Apr-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements