Continuing code after executing a File - Python
Question: I have made a Simple GUI that launches when i run my Twitch TV IRC Bot. But,
the main bot doesn't continue until after i close the GUI. How would i make it
so the Script runs at the same time as the GUI? This is the GUI:

    
    
    ##--GUI--##
    def whitelist_wipe():
    execfile('command_whitelist_wipe.py')
    
    def modpack():
    modpack = modpack_input.get()
    return
    
    
    
    root = Tk()
    modpack_input = StringVar()
    
    root.title('Geekster_Bot')
    root.geometry('450x450+500+300')
    
    WhitelistButton = Button(root, text = 'Clear Whitelist!', command + whitelist_wipe).pack()
    
    SubmitButton = Button(root, text = 'Change Modpack', command = modpack).pack()
    
    ModpackName = Entry(root, textvariable=modpack_input).pack()
    
    root.mainloop()
    

This is the part where it launches the GUI from the main Bot scrpit:

    
    
    try:
        execfile('GUI.py')
    
    except:
        print('Error loading GUI')
    

How would i continue the code with the GUI open?

EDIT

GUI.py;

    
    
    ##--GUI--##
    def whitelist_wipe():
        execfile('command_whitelist_wipe.py')
    
    def modpack_var():
        modpack_input = modpack_user.get()
    
    
    
    root = Tk()
    modpack_user = StringVar()
    
    root.title('Geekster_Bot')
    root.geometry('350x100+500+300')
    
    Label1 = Label(root, text = 'Geekster_Bot Controls!').pack()
    
    WhitelistButton = Button(root, text = 'Clear Whitelist!', command =whitelist_wipe).pack(side = LEFT)
    
    
    SubmitButton = Button(root, text = 'Change Modpack', command = modpack_var).pack()
    
    ModpackName = Entry(root, textvariable=modpack_user).pack()
    
    root.mainloop()
    

Main Bot;

    
    
    try:
        #Create thread
        gui_thread = threading.Thread( target = execfile, args = ('GUI.py',) )
        #Start thread
        gui_thread.start()
        #Code to run in the main thread
    
    except:
        print('Error loading GUI')
    
    def message(msg): #function for sending messages to the IRC chat
                global queue
                queue = queue + 1
                print queue
                if queue < 20: #ensures does not send >20 msgs per 30 seconds.
                    twitch = ('OUTPUT ON ' + channel + ' :' + msg + '\r\n')
                    irc.send('PRIVMSG ' + channel + ' :' + msg + '\r\n')
                    print (twitch)
                else:
                    print 'Message deleted'
    
    def socialtimer(): #function for announcing social every 3 minutes
                global ntimer
                z = open(r'E:\Geekster_Bot\Twitter.txt')
                SOCIAL = z.read()
                message (SOCIAL)
                print 'Social Timers Started!'
                ntimer = threading.Timer(1200,socialtimer)
                ntimer.start()
    
    def queuetimer(): #function for resetting the queue every 30 seconds
                global queue
                print 'queue reset'
                queue = 0
                threading.Timer(30,queuetimer).start()
    
    def modpack_var():
                modpack_input = modpack_user.get()
    
    ##--Main Bot--##
    
    #General variables
    newsmsg = 'whitelist'
    modpack = modpack_input
    


Answer: Since the gui itself runs in a loop it blocks the thread you start it in until
you stop the loop (close the gui). You need to start the gui in a different
thread from the main one.

You can do this using the threading module:

    
    
    import threading
    
    try:
        #Create thread
        gui_thread = threading.Thread( target = execfile, args = ('GUI.py',) )
        #Start thread
        gui_thread.start()
        #Code to run in the main thread
    
    except:
        print('Error loading GUI')
    

In this code the `gui_thread` object is a thread, which runs the `execfile`
callable (a function in this case) with the parameter `'GUI.py'` on start.
Check the threading module documentation for further info:
<https://docs.python.org/3.3/library/threading.html>

