循环继续后继续代码? [英] Continue code after loop continues?

查看:44
本文介绍了循环继续后继续代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发布了一个类似的问题,但在完成建议的项目后,我遇到了类似的问题,但代码更改了很多,所以我认为最好查看干净的代码!

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!

我正在制作一个非恶意的 Twitch 电视机器人,它可以在聊天中运行一些命令.我已经使用该机器人 2 个月了,并决定创建一个小型 GUI,以便在它运行时对变量进行基本更改.GUI 和 Bot 都可以单独正常工作,但我在让它们一起工作时遇到了问题.我一般是线程和 python 的新手,所以我真的被困在如何解决这个问题上.

I am making a Non-malicious Twitch TV bot that runs a few commands in chat. 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. Both the GUI and the Bot work fine separately but i am having issues making them work together. I am new to threading and python in general so i am truly stuck on how to fix this.

我使用 Tkinter 创建了 GUI,它需要一个循环来使窗口保持打开状态.因此,此循环会停止其余代码继续运行并启动机器人.我需要弄清楚如何保持循环运行,同时还要继续运行 Bot 的其余部分并在 GUI 后面运行它.

I have used Tkinter to create the GUI and it requires a Loop to make the window remain open. 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.

这是机器人启动 GUI 的开始;

This is the start of the Bot where it launches the GUI;

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

然后它继续连接到 IRC.

It then continues to the bot connecting to the IRC.

如何在 mainloop() 之后继续?

先谢谢了!

推荐答案

您可以使用 线程多处理.简单例子:

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

但是...通常最好将 GUI 保留在主线程中.

But...it's generally best to keep the GUI in the main thread.

这篇关于循环继续后继续代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆