tkinter popup code example
Example 1: popups in tkinter
from tkinter import messagebox
messagebox.showinfo(title="Error", message="No Data File Found.")
Example 2: make a pop up window in python
from tkinter import *
def alert_popup(title, message, path):
"""Generate a pop-up window for special messages."""
root = Tk()
root.title(title)
w = 400
h = 200
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
x = (sw - w)/2
y = (sh - h)/2
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
m = message
m += '\n'
m += path
w = Label(root, text=m, width=120, height=10)
w.pack()
b = Button(root, text="OK", command=root.destroy, width=10)
b.pack()
mainloop()
Example 3: popup window python tkinter
import tkinter as tk
def popupmsg(msg, title):
root = tk.Tk()
root.title(title)
label = ttk.Label(root, text=msg)
label.pack(side="top", fill="x", pady=10)
B1 = tk.Button(root, text="Okay", command = root.destroy)
B1.pack()
popup.mainloop()
Example 4: tkinter popup menu
def do_popup(self,event):
try:
self.popup_menu.tk_popup(event.x_root,
event.y_root)
finally:
self.popup_menu.grab_release()