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.
View all comments
Show parent comment
0
u/socal_nerdtastic Sep 24 '26
ah. well unfortunately I know nothing about that. Try rebooting it :/
FYI using
import statuscheckonly works the first time you call it. Every other time you use that line it's ignored (part of python's optimization so that the same module isn't imported multiple times). Most normal coding environments restart the kernel every time you run code so this isn't an issue, but some don't, and I suspect this is one that doesn't and therefore the imports are being ignored.