python tkinter messagebox code example
Example 1: how to make alert dialog in tkinter
import tkinter as tk
from tkinter import messagebox as mb
def answer():
mb.showerror("Answer", "Sorry, no answer available")
def callback():
if mb.askyesno('Verify', 'Really quit?'):
mb.showwarning('Yes', 'Not yet implemented')
else:
mb.showinfo('No', 'Quit has been cancelled')
tk.Button(text='Quit', command=callback).pack(fill=tk.X)
tk.Button(text='Answer', command=answer).pack(fill=tk.X)
tk.mainloop()
Example 2: python tkinter messagebox
import tkinter
from tkinter import messagebox
root = tkinter.Tk()
messagebox.showerror("Error", "Error message")
messagebox.showwarning("Warning","Warning message")
messagebox.showinfo("Information","Informative message")
Example 3: tkinter info box
from tkinter import messagebox
messagebox.showinfo('Title', 'Information')
Example 4: tkinter messagebox
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def hello():
tkMessageBox.showinfo("Say Hello", "Hello World")
B1 = Tkinter.Button(top, text = "Say Hello", command = hello)
B1.pack()
top.mainloop()
Example 5: list in tkinter messagebox
from tkinter import *
from tkinter import messagebox
def listMessageBox(arr):
window=Tk()
listbox=Listbox(window)
listbox.pack(fill=BOTH, expand=1)
[listbox.insert(END, row) for row in arr]
window.mainloop()
arr=['a','b','c','1','2','3']
listMessageBox(arr)