python logo

tkinter askquestion


Python hosting: Host, run, and code Python in the cloud!

Tkinter supports showing a message box. Tkinter is a GUI library for Python, it lets you make desktop applications.

The implementation you need depends on your Python version, you should use Python 3 or newer (2 is legacy).

To test your Python version:

python -- version

Related course

Tkinter question dialog

Tkinter can be used to crete a prompt that ask the users a question.

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

download tkinter examples

Next





Leave a Reply: