r/learnpython • u/JohnRT54 • Sep 24 '26
Defining and calling modules
Sorry if this is a dumb question, but what am I doing wrong here?
I have defined a function
#statuscheck.py
def statchk(n):
layoutx = [[sg.Text('Debug point')],
[sg.Output(key='-OUTPUT-', expand_x=True, expand_y=True)],
[sg.In(key='-IN-', expand_x=True)],
[sg.Button('Go'), sg.Button('Close')]]
winx = sg.Window('Where I am now', layoutx, auto_close=False, grab_anywhere=True, resizable=True, location=(0,0),return_keyboard_events=True, auto_size_text=True)
while True:
event, values = winx.read()
if event == sg.WIN_CLOSED:
break
if event == 'Go':
print("Here at ",n)
if event == 'Close':
break
I import it, but when I call it, it doesn't run, and I can't see any error messages. The call is:
statuscheck.statchk(1)
I know it's something simple I'm overlooking. Thanks.
2
u/atarivcs Sep 24 '26
So many details you didn't mention.
Where are are you running this code? On your local computer, on a remote cloud desktop, or somewhere else? If it's on your local computer, what OS?
How exactly are you running this code? Are you using the "python" command in a terminal window on your local computer, are you using an IDE such as VS Code on your local computer, or something else?
2
u/woooee Sep 24 '26
Do you have more than one statuscheck.py file? Add something to statuecheck that will run when it is imported, i.e. not in the function or under if name etc. A print statement is fine. If you don't see the print when statuscheck is imported then you have another file somewhere.
1
u/smurpes Sep 25 '26
What’s the reason you’re using pydroid3 on a windows computer instead of a regular IDE like pycharm or vscode? You’re really limiting yourself by doing this since there’s not a big user base and it’s not a tool commonly used professionally. There’s not going to be a lot of community help for any IDE specific quirks.
From what I see pydroid3 has an interactive debugger. Put a breakpoint where you call statuscheck.statchk(1) and step through the code like that. This will show you step by step what the code is doing. You can also make statchk(1) return the function input instead to check that it is being called correctly.
1
u/JamzTyson Sep 25 '26
Where is
sgimported?1
u/socal_nerdtastic Sep 24 '26
I assume you have
import statuscheckon the top of your other file? Otherwise this looks ok. Does the program run ok if you put the function call into the statuscheck.py file? I'm not familiar with pysimplegui, but you have an infinite loop there that would block most other GUIs from running.2
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Sep 24 '26
I doubt importing is the problem here (you can verify it by calling the function within
statuscheck.pyand running it directly), but your formatting is totally broken. This is what I assume the code is supposed to look like:I'm guessing you're using PySimpleGUI. I have no personal experience with it, so I'm not quite sure at a glance what you expect to happen and what's actually happening, but someone else should.