Tkinter 询问对话框

Tkinter 支持显示消息框。你需要的实现取决于你的 Python 版本。要测试你的版本:

python --version

Tkinter 问题对话框

Tkinter 可用于询问用户问题。

Python 2.x 版本:

import Tkinter
import tkMessageBox

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

Python 3.x 版本:

import tkinter
from tkinter import messagebox

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

结果:

tk 询问对话框

Tkinter 消息框

此代码将打开一些 Tkinter 问题框:

Python 2.x 版本:

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.x 版本:

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?")

结果:

Tk 问题框