You can get a list of all the python command flags and what they do by typing
python --help
In the case of tkinter, you need to run with the -i flag because it will run in "interactive mode". This allows the windowed application to launch. The help says it best
-i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x
Meanwhile -m launches a module as if it were a script.
Answer from Soviut on Stack Overflow-m mod : run library module as a script (terminates option list)
tkinter - What is the meaning of command line options for python from the windows command prompt (example: -i, -m) - Stack Overflow
Python's many command-line utilities
python - How do I access command line arguments? - Stack Overflow
Command Line Arguments
Can someone explain to me the concept of the command line, and what it means to be running from a command line argument in python?
The 'command line' is referring to a way of interacting with the files and programs on your computer in a text-based (as opposed to graphical) manner. How you access it depends a lot on what kind of system you are using. Here is a crash course if you want to learn more about the command line in general.
(I know I just linked to LPTHW, which is frowned upon in this subreddit, but his command line crash course is genuinely quite good for beginners and is free. Please no one freak out.)
Also, is there a reason that when I try to execute a program, it creates a window that closes almost immediately?
Yes, this is a thing Windows does. It thinks the program is all done, and 'conveniently' closes the window for you. Try adding an input() to the end of your code to keep the window open, or run your code from the command line.
aspects of a code outside of the syntax, such as how the computer knows how to read it, and how it's meant to interact with other programs
That's a pretty broad question, but here's a stackexchange answer that might be relevant.
More on reddit.comVideos
Python 3.12 comes bundled with 50 command-line tools.
For example, python -m webbrowser http://example.com opens a web browser, python -m sqlite3 launches a sqlite prompt, and python -m ast my_file.py shows the abstract syntax tree for a given Python file.
I've dug into each of them and categorized them based on their purpose and how useful they are.
Python's many command-line tools
Python tutorial explains it:
import sys
print(sys.argv)
More specifically, if you run python example.py one two three:
>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']
I highly recommend argparse which comes with Python 2.7 and later.
The argparse module reduces boiler plate code and makes your code more robust, because the module handles all standard use cases (including subcommands), generates the help and usage for you, checks and sanitize the user input - all stuff you have to worry about when you are using sys.argv approach. And it is for free (built-in).
Here a small example:
import argparse
parser = argparse.ArgumentParser("simple_example")
parser.add_argument("counter", help="An integer will be increased by 1 and printed.", type=int)
args = parser.parse_args()
print(args.counter + 1)
and the output for python prog.py -h
usage: simple_example [-h] counter
positional arguments:
counter counter will be increased by 1 and printed.
optional arguments:
-h, --help show this help message and exit
and the output for python prog.py 1 As one would expect:
2