【问题标题】:Making a discordbot gui制作 discordbot gui
【发布时间】:2020-01-02 19:03:03
【问题描述】:

我正在尝试为我的不和谐机器人制作一个 gui(使用 Tkinter),但问题是当我单击“启动机器人”按钮时,机器人实际上启动了,但整个程序崩溃了。我应该怎么做才能修复它?

from tkinter import *
from discord.ext import commands

client = commands.Bot(command_prefix='.')

window = Tk()

window.title("Bot")

window.geometry('350x200')


def clicked():
    @client.event
    async def on_ready():
        print("ready")
    client.run('')


btn = Button(window,text='Start bot', command=clicked)


btn.grid(column=1,row=1)

window.mainloop()

【问题讨论】:

  • 阅读asyncio.runedit您的问题并详细解释/显示“整个程序崩溃”
  • client.run 被阻塞,所以当你运行你的机器人时,tkinter 不再能够更新并因此崩溃

标签: python python-3.x tkinter discord discord.py


【解决方案1】:

你遇到了和我一样的问题!

午睡后(我一个星期没睡)我发现你需要关闭窗口window.destroy()并用所有按钮重新打开它

window = Tk()
btn.pack()

【讨论】:

    【解决方案2】:

    你应该看看 Threads,因为它可以让你独立运行 Discord 和 Tkinter 窗口。这是必需的,因为 client.run() 是阻塞的,因此当该函数运行时,它不会进一步执行您的代码,因此不会运行 Tkinter 主循环以允许 GUI 更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-29
      • 2020-11-24
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2021-11-23
      相关资源
      最近更新 更多