简体   繁体   English

循环继续后继续代码吗?

[英]Continue code after loop continues?

I recently posted a similar question but after doing the suggested items i had a similar issue, but the code was changed a lot, so i thought it would be best to see clean code! 我最近发布了一个类似的问题,但是在执行建议的项目后,我也遇到了类似的问题,但是代码进行了很多更改,因此我认为最好查看简洁的代码!

I am making a Non-malicious Twitch TV bot that runs a few commands in chat. 我正在制作一个在聊天中运行一些命令的非恶意Twitch TV机器人。 I have been using the bot for 2 months and decided to create a small GUI for basic changes to variables whilst it is running. 我已经使用机器人2个月了,并决定创建一个小的GUI,以便在变量运行时对其进行基本更改。 Both the GUI and the Bot work fine separately but i am having issues making them work together. GUI和Bot分别可以正常工作,但是我在使它们协同工作时遇到问题。 I am new to threading and python in general so i am truly stuck on how to fix this. 我是线程和python的新手,所以我真的对如何解决这个问题感到困惑。

I have used Tkinter to create the GUI and it requires a Loop to make the window remain open. 我已经使用Tkinter创建了GUI,它需要一个Loop来使窗口保持打开状态。 This loop therefore stops the rest of the code continuing on and launching the bot. 因此,此循环将停止其余代码继续运行并启动机器人。 I need to work out how to keep the loop running but also continuing on to the rest of the Bot and run that behind the GUI. 我需要弄清楚如何保持循环运行,还要继续到Bot的其余部分并在GUI后面运行它。

This is the start of the Bot where it launches the GUI; 这是Bot启动GUI的开始。

app = Geekster_Bot_GUI(None)
app.title('Geekster_Bot')
app.geometry('450x100')
app.mainloop()

It then continues to the bot connecting to the IRC. 然后,它继续连接到IRC的机器人。

How do i continue after the mainloop() ? mainloop()之后如何继续?

Thanks in advanced! 提前致谢!

You can use threading or multiprocessing . 您可以使用线程或多处理 Simple example: 简单的例子:

import Tkinter
import threading

def create_frame():
    MessFrame = Tkinter.Tk()
    MessFrame.geometry('800x400+200+200')
    MessFrame.title('Main Frame')
    Framelabel = Tkinter.Label(MessFrame, text='Text Here', fg= 'red')
    Framelabel.place(x=10,y=10)
    MessFrame.mainloop()


t1 = threading.Thread(target=create_frame)
t1.start()

#continue
print 1234

But...it's generally best to keep the GUI in the main thread. 但是...通常最好将GUI保留在主线程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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