I've been trying all sort of things but I can't seem to get the two to work together. I was trying to display the messages I receive on telegram to a Tkinter GUI. I can't run them on separate threads because the telethon client wouldn't be able to interact with the tkinter labels.
Here's the basic structure of my code:
client = TelegramClient('robot', api_id, api_hash)
root = tk.Tk()
root.title("Telegram Watcher")
root.geometry("300x350")
some_label = tk.Label(root, text='Last Message')
some_label.pack()
@client.on(events.NewMessage(chats=channel))
async def my_event_handler(event):
some_label.config(text=event.raw_text)
# or some other things I could do with the root tkinter
client.start()
client.run_until_disconnected()
root.mainloop()
I know root.mainloop() will never start because client.run_until_disconnected() is already running as a loop. I have already tried threading and client.loop.run_until_complete(main()) but nothing here works as I intended. I am not too familiar in using async and await either.
Is there anyway to code this in a simple way? Thank you in advance