So I have a login script called login.py
. When user log in, script will create a user session and execute main.py
and close login.py
. How to do this?
Asked
Active
Viewed 114 times
-1

makifv
- 27
- 1
- 5
-
https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another – Paul Burkart Jun 07 '21 at 16:20
-
Run in the same console or a different console? By "close login.py" you infer run in a different console. – Amiga500 Jun 07 '21 at 17:01
2 Answers
0
I'm a little confused by what you need help with but try this:
from fileName import function_you_want
Ideally you don't want a script to run on an import. It can cause some unexpected things to happen. At the bottom of main.py I would use this:
if __name__ == "__main__":
call_your_function()
This way you can do tests by running the script directly or calling a specific method from another py file without running the script.

Peter Jones
- 191
- 5
0
What you can do is import that file main.py
like import main
. If you want everything from that file, from main import *
Then, after the user logins, destroy your main window using <Tk>.destroy()
and then call your function.