[Python] Tkinter message box

python 2 已成為絕響,我們直接學習 python3 吧。

教學文章:
https://morvanzhou.github.io/tutorials/python-basic/tkinter/2-10-messagebox/

from tkinter import messagebox
messagebox.showinfo("Title", "a Tk MessageBox")

Tkinter showerror, showwarning and showinfo

Tkinter includes several other message boxes:

  • showerror()
  • showwarning()
  • showinfo()
import tkinter
from tkinter import messagebox
hide main window
root = tkinter.Tk()
root.withdraw()
message box display
messagebox.showerror("Error", "Error message")
messagebox.showwarning("Warning","Warning message")
messagebox.showinfo("Information","Informative message")

請服用下面的 code 讓程式在 python2 & python3 都可以run:

try:
# for Python2
from Tkinter import *
import ttk
import tkMessageBox as messagebox
except ImportError:
# for Python3
from tkinter import *
from tkinter import ttk
from tkinter import messagebox

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *