Launch Python GUI Apps Without a Command Prompt Window

This guide shows several ways to start Python graphical applications—by renaming scripts to .pyw, using batch files, or building a PyQt5 launch toolbox—so you can run them instantly without opening a black command‑prompt window.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Launch Python GUI Apps Without a Command Prompt Window

So far this public account has introduced many graphical applications such as a number‑guessing game, PDF reader, snake game, and weather query tool. While packaging them into an exe file is convenient for distribution, it is unnecessary for personal use; a quick launch without a bulky exe is sufficient.

Python built‑in method

The simplest way is to rename a .py file to .pyw, which causes Windows to run it with pythonw.exe. This eliminates the black command‑prompt window and prevents the program from closing when the window is closed.

You can then create a desktop shortcut, change its icon in the properties, and have a graphical shortcut for quick launching.

Batch file method

This approach is similar to the first one but uses a .bat file to invoke pythonw.exe on the .pyw script.

Create a text file with the following two lines and save it as .bat. The first string after start is the path to pythonw.exe (usually in the same directory as python.exe), and the second string is the absolute path to your .pyw program.

@echo off
start  "D:\python372\pythonw.exe" "D:\QQPCMgr\Desktop\Pytho高效编程\start.pyw"

You can also create a shortcut for the batch file and change its icon.

Implementing a launch toolbox with PyQt5

The following example demonstrates a PyQt5‑based launch toolbox that provides three main features:

Execute Python programs directly from a toolbar.

Right‑click on a 3×3 grid to save or delete quick‑launch links.

Left‑click on a grid cell to display the associated graphical interface.

The toolbox can be packaged as an .exe or renamed to .pyw and given a shortcut for easy use.

Key point 1: The program launches a new process to run the target .py file. Because the launch manager’s working directory is its own path, you must use absolute paths for programs like a PDF reader; otherwise, add os.chdir(os.path.dirname(os.path.realpath(__file__))) to set the correct working directory.

os.chdir(os.path.dirname(os.path.realpath(__file__)))

Key point 2: Use QProcess to manage processes. Create a QProcess object and call startDetached so the child process runs independently of the main launcher.

from PyQt5.QtCore import QProcess

def open(self):
    fname = self.get_file()
    if fname:
        process = QProcess()
        process.startDetached('python', [fname])

Key point 3: Override the button class to support a right‑click context menu and custom actions. The button stores its name, target path, and state (whether a path is bound).

class MyButton(QPushButton):
    def __init__(self, parent=None):
        super(MyButton, self).__init__(parent)

Additional functionalities include setting font size/style, adding right‑click menu actions (add, delete), and redefining left‑click behavior.

Key point 4: Interact with a database to persist button information, using a context manager for readability.

def save2db(start):
    with DBManger(starter) as conn:
        conn.execute("INSERT INTO starter Values (?,?,?)", (start.fname, start.name, start.state))
        conn.commit()

That covers the essential steps; feel free to share and support the project.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GUIPythonProcess ManagementPyQt5Batch filepyw
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.