【发布时间】: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.run和edit您的问题并详细解释/显示“整个程序崩溃”
-
client.run被阻塞,所以当你运行你的机器人时,tkinter 不再能够更新并因此崩溃
标签: python python-3.x tkinter discord discord.py