Web Analytics Made Easy - Statcounter
Skip to content

No Console Launching

Windows 10

You've just coded up your nice GUI, ready for that "Windows experience".... you double click your .py file in Windows explorer and up comes 2 windows, a console and your GUI Window.

If you're ready for a more Windows-like experience for you and your users, then these steps should get you there.

There are a couple of simple tricks needed.

Rename Your .py to .pyw

  1. Rename your .py file to .pyw
  2. Launch it using pythonw.exe instead of python.exe

When you right click on your .pyw file, you'll want to associate it with pythonw.exe if that's not already been done by Python for you when it was installed.

Right click your .pyw file and choose "Properties"

You'll see a window like this which will tell you what will open the file if you double click it. You can click the "Change..." button to change what opens the file.

image

Make A Shortcut

You've learned how to use explorer to double-click and launch your GUI window without a console. Let's go 1 step further.

If you were to simply drag your .pyw file to your taskbar to "pin" it for quick launching, unfortunately that doesn't work. It'll try and launch Python instead.

What we're going to do is make an icon/shortcut to your python program that you can place anywhere AND you can also pin it to your taskbar.

To make a shortcut, right click your .pyw file and choose "Create Shortcut". It's near the end of the list of right click options

image

My program is called Demo_Desktop_Widget_Launcher_Bar.pyw. After I created the shortcut, a file named Demo_Desktop_Widget_Launcher_Bar.pyw - Shortcut was created in the same folder.

You should now do these 2 operations on that shortcut 1. Rename it something that looks like any other program 2. Choose an icon for your shortcut. On windows, this needs to be a .ICO file 3. Set a specific program that opens it (your pythonw.exe file)

I named my shortcut "Launcher".

Because I wanted the 3.9 version of Python to open this specific program, I added pythonw.exe part to the target field in the properties. After the pythonw.exe add your full path to your .pyw file. If there are any spaces, put "" around it. It should look something like this:

image

In my folder with my program, I now see the shortcut with the icon I chose earlier

image

Double-clicking this icon will start your .pyw file without a console. It will look "like a real windows program"

Pin Your Shortcut

If you want to be able to quickly launch your program, you can "pin" your shortcut to your taskbar. To do this, you can drag and drop the icon onto the taskbar. Or, you can right click the icon and choose "pin to taskbar".

After pinning it, I see this as my taskbar. The launcher icon is there ready to be clicked. When I click it, the program runs without any console windows.

image

This particular .pyw file is the Demo Launcher Bar. Clicking the icon launches this launcher.

A7arqWk7eB


Themes - Window "Beautification"

"Beautiful windows" don't just happen, but coloring your window can be accomplished with 1 line of code.

One complaint about tkinter that is often heard is how "ugly" it looks. You can do something about that by using PySimpleGUI themes.

sg.theme('Dark Green 5')

A call to theme will set the colors to be used when creating windows. It sets text color, background color, input field colors, button color,.... 13 different settings are changed.

The default theme is "Dark Blue 3"

Look and Feel Theme Explosion

There are currently 140 themes to choose from (in April 2020, maybe more by the time you read this)

SNAG-0620

To see the above preview for your version of PySimpleGUI, make this call to generate a preview of all available themes:

sg.theme_previewer()

Even windows that are created for you, such as popups, will use the color settings you specify. And, you can change them at any point, even mid-way through defining a window layout.

This one line of code helps, but it's not the only thing that is going to make your window attractive.

Theme Name Format

You can look at the table of available themes to get the name of a theme you want to try, or you can "guess" at one using this formula:

<"Dark" | "Light"> <Color> [#]

Where Color is one of these:

Black, Blue, Green, Teal, Brown, Yellow, Gray, Purple

The # is optional and is used when there is more than 1 choice for a color. For example, for "Dark Blue" there are 12 different themes (Dark Blue, and Dark Blue 1-11). These colors specify the rough color of the background. These can vary wildly so you'll have to try them out to see what you like the best.