Reputation: 21
I'm trying to make a gui(using Tkinter) for my discord bot but the problem is when I click button 'Start bot' the bot actually starts but the whole program crashes. What should I do to fix it?
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()
Upvotes: 0
Views: 2503
Reputation:
you are getting the same problem i did!
After having a nap (i haven't slept in a week) i figured out that you need to close the window window.destroy()
and reopen it with all buttons
window = Tk()
btn.pack()
Upvotes: 0
Reputation: 311
You should have a look at Threads as it will allow you to run both Discord and the Tkinter window independently. This is needed as client.run() is blocking, so when that function is run it will not execute any further down your code, and therefore won't run the Tkinter main-loop to allow the GUI to update.
Upvotes: 1