Reading about Python? Actually practice it. Try PyChallenge free

Python Tutorial

tkinter askquestion dialog

Tkinter supports showing a message box. The implementation you need depends on your Python version. To test your version:

python -- version

Related course
Practice Python with interactive exercises

Tkinter question dialog

Tkinter can be used to ask the users questions.

Python 2.x The Python 2.x version:

import Tkinter
import tkMessageBox

result = tkMessageBox.askyesno("Python","Would you like to save the data?") print result

Python 3 The Python 3.x version:

import tkinter
from tkinter import messagebox
 
messagebox.askokcancel("Python","Would you like to save the data?")

Result:

tk question tk question

Tkinter message boxes

This code will open some Tkinter question boxes:

Python 2.7 The Python 2.x version:

import Tkinter
import tkMessageBox

# Confirmation messagebox tkMessageBox.askokcancel("Title","The application will be closed")

# Option messagebox tkMessageBox.askyesno("Title","Do you want to save?")

# Try again messagebox tkMessageBox.askretrycancel("Title","Installation failed, try again?")

Python 3 The Python 3.x version:

import tkinter
from tkinter import messagebox
 
messagebox.askokcancel("Title","The application will be closed")
messagebox.askyesno("Title","Do you want to save?")
messagebox.askretrycancel("Title","Installation failed, try again?")

Result:

questions tk Tk question box

Next