loki locus
loki locus

Reputation: 73

Make opening of cmd window optional in a tkinter app?

Is there a way I can make the opening of the cmd window optional in a python GUI app, like if option xyz is given, open an cmd window otherwise don't?

import sys
import tkinter
master = tkinter.Tk()
#tk gui stuff goes here
if sys.argv[1] == "console":
    #open cmd winow
master.mainloop()

I was planning to only open the cmd window if the user wants to see the debugging output etc.

Upvotes: 0

Views: 2963

Answers (2)

dkelaty
dkelaty

Reputation: 5

you need to save your python file as a .pyw file instead of a .py
Note that you might need to copy the text of your program into textedit or Notepad and save it as a .pyw from there.

Upvotes: 0

saud
saud

Reputation: 718

This may not be a complete solution, but it works. And is dead simple:

If you run the python script using pythonw instead of the usual python, it will run without a cmd window in the background.

For example:

> pythonw my_app.py

And if you want the cmd window open,

> python my_app.py

You could also change the extension of the script from .py to .pyw to avoid opening the cmd window.

Upvotes: 2

Related Questions