I am trying to create a chat server where multiple clients can connect to a server. I want to create a GUI in one module (say clientgui.py) which calls another module (say client.py) to connect to the server.
The problem is I have to call client.py when a certain button is clicked. But while doing so, the main loop never gets executed. For example,
app = Tk()
...
sendbutton = Button(text,height...., command = Client().senddata())
#This will call function of a different module.
....
app.mainloop()
Is it possible to call another module inside a “GUI loop”?
You are not assigning the function to
command, but the result ofsenddata. Try this instead:That should solve your problem. Notice how the
senddatamethod has no parenthesis on it? That is because you don’t want to call it right there, you want to talk about it. Since functions and methods are objects, it is ok to assign it to a parameter (e.g.command).What your code was doing, was assign the result of calling
Client().senddata()to the buttons command. I assume this doesn’t return a function/method/callable object (but it could) and that instead you assignNone, in effect making the button not do anything at all when clicked.