- 1 year ago
Simple Windows Popup Window using Python
To create a simple popup window using Python on Windows, you can use the tkinter
library, which provides a way to create GUI applications. Here's an example:
pythonimport tkinter as tk
from tkinter import messagebox
def show_popup():
messagebox.showinfo("Popup", "Hello, World!")
# Create the main window
root = tk.Tk()
# Create a button that triggers the popup
button = tk.Button(root, text="Show Popup", command=show_popup)
button.pack()
# Run the main event loop
root.mainloop()
In this example, we import the necessary modules from tkinter
to create the popup window. The show_popup
function is triggered when the button is clicked, and it displays a simple information message box with the title "Popup" and the message "Hello, World!".
To run this code, save it to a Python file (e.g., popup.py
) and execute it using a Python interpreter. A window will appear with a button labeled "Show Popup". Clicking the button will display the popup message box.
You can customize the popup window further by exploring other methods available in the messagebox
module, such as showwarning
, showerror
, or askquestion
, depending on your specific needs.
Please note that the tkinter
library is built-in with Python, so you don't need to install any additional packages to use it for creating simple GUI applications on Windows.