import tkinter as tk from tkinter import ttk LARGE_FONT= ("Verdana", 12) NORM_FONT= ("Verdana", 10) SMALL_FONT= ("Verdana", 8) def popup_msg(msg): '''Displays a message in a pop-up''' popup = tk.Tk() popup.wm_title("! message") window_width = 640 window_height = 480 # get the screen dimension screen_width = popup.winfo_screenwidth() screen_height = popup.winfo_screenheight() # find the center point center_x = int(screen_width/2 - window_width / 2) center_y = int(screen_height/2 - window_height / 2) # set the position of the window to the center of the screen popup.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}') label = ttk.Label(popup, text=msg, font=NORM_FONT) label.pack(side="top", fill="x", pady=10) B1 = ttk.Button(popup, text="Dismiss", command = popup.destroy) B1.pack() popup.mainloop() def popup_prompt(msg, func, btn_title="click", dismiss_after_click=True): '''Displays a pop-up with a button and runs a function on click of the button''' popup = tk.Tk() popup.wm_title("? prompt") window_width = 640 window_height = 480 # get the screen dimension screen_width = popup.winfo_screenwidth() screen_height = popup.winfo_screenheight() # find the center point center_x = int(screen_width/2 - window_width / 2) center_y = int(screen_height/2 - window_height / 2) # set the position of the window to the center of the screen popup.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}') label = ttk.Label(popup, text=msg, font=NORM_FONT) label.pack(side="top", fill="x", pady=10) command = lambda : [popup.destroy(), func()] B1 = ttk.Button(popup, text=btn_title, command=command) B1.pack() popup.mainloop()