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 問題框