To create a pop-up window in a Python GUI, use a dialog or a secondary window from your toolkit. In Tkinter, call messagebox.showinfo() for a simple message or create a tk.Toplevel for a custom window. In PyQt6, use QMessageBox for messages or subclass QDialog for custom content.
Tkinter ships with Python, while PyQt6 (or PySide6) is installed with pip install PyQt6. The examples below work on Python 3.9 and later and cover simple message boxes, custom windows and modal behaviour.
The tkinter.messagebox module provides ready-made dialogs for information, warnings, errors and yes/no questions.
Available helpers include showinfo, showwarning, showerror, askyesno, askokcancel, askretrycancel and askquestion. They block until the user answers and return the result.
Use tk.Toplevel when you need your own widgets. Setting transient and grab_set makes it behave like a modal dialog.
wait_window() pauses the calling code until the dialog is destroyed, so you can read dialog.result straight afterwards. Always set a parent so the dialog is closed with the main window.
QMessageBox has static helpers similar to Tkinter's.
PyQt6 uses fully scoped enums such as QMessageBox.StandardButton.Yes. The old short form from PyQt5 (QMessageBox.Yes) does not work in PyQt6.
Subclass QDialog to build your own pop-up. Use exec() for a modal dialog that blocks, or show() for a non-modal window.
QDialogButtonBox gives platform-correct button order and wires up accept and reject for you.
| Behaviour | Tkinter | PyQt6 |
|---|---|---|
| Modal (blocks the parent) | grab_set() plus wait_window() | dialog.exec() |
| Non-modal (parent stays usable) | Toplevel without grab_set() | dialog.show() |
| Keep above the parent | transient(parent) | Pass parent to the constructor |
| Close from code | destroy() | accept(), reject() or close() |
Prefer modal dialogs only when the user must answer before continuing. For notifications that should not interrupt work, use a non-modal window or a status bar message.
With Tkinter, messagebox.showinfo("Title", "Message"). With PyQt6, QMessageBox.information(parent, "Title", "Message").
You probably did not set a parent or call transient(parent). Pass the parent to Toplevel and call lift() or focus_force() if needed.
Store the result on the dialog object and read it after the dialog closes. In Tkinter use wait_window(), and in PyQt6 check the return value of exec() and then read the fields.
Avoid it. Use one tk.Tk() and create other windows as Toplevel. A second root creates a separate Tcl interpreter and causes confusing bugs with variables and images.
Use messagebox or QMessageBox for quick messages, and Toplevel or QDialog for custom pop-ups. Always pass a parent, make dialogs modal only when needed, and return results through the dialog object after it closes.