popup window tkinter code example

Example 1: popups in tkinter

from tkinter import messagebox
messagebox.showinfo(title="Error", message="No Data File Found.")

Example 2: 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 3: tkinter popup menu

#display menu on right click
    def do_popup(self,event):
        try:
            self.popup_menu.tk_popup(event.x_root,
                                     event.y_root)
        finally:
            self.popup_menu.grab_release()