简体   繁体   中英

Call main methods from a outside module in python

I am making a GUI with the wxPython Libraries. I have some modules. The application beggins with a main function that call to a Main Controller. Like this:

from controller.mainController import MainController

if __name__ == '__main__':

    createGUI()

def createGUI():
    """
    Create the GUI
    """
    app = wx.App(False)
    host = MainController(app)
    app.MainLoop()

def readTerminal():
    terminal = consola.Console()
    try:
        terminal.cmdloop("Hola!")
        terminal.cmdloop("Fallo en la linea dos")
    except KeyboardInterrupt:
        terminal.do_quit(None)

I want to call readTerminal() function from another module. The modules are writing in different files. What can I do that?

If both the main module and other modules need to call readTerminal , then that function should be put into a common module that they can both import from. I usually have a controller module or a utility module where I can keep functions like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM