You can try iterative refactoring. On the first pass, just import flask.
Check for a numeric command line parameter.
If found, that is your port, and you are in server mode.
Start up flask (the tkinter part won't be used at all in this mode).
Respond to GET requests with some simple HTML that says "Hello world" or something.
If the command line parameter is not found, just run normally in tkinter mode, and don't start up flask.
You can try iterative refactoring. On the first pass, just import flask. Check for a numeric command line parameter. If found, that is your port, and you are in server mode. Start up flask (the tkinter part won't be used at all in this mode). Respond to GET requests with some simple HTML that says "Hello world" or something. If the command line parameter is not found, just run normally in tkinter mode, and don't start up flask.