【发布时间】:2020-09-19 07:52:18
【问题描述】:
我在下面有这个异步功能,基本上我想使用 tkinter 将它放入按钮的命令中。
async def main():
await client.send_message('username', 'message')
with client:
client.loop.run_until_complete(main())
在message 中,我想将变量cpf 放在我的代码中,但我不知道应该如何将它们放在一起。我对python很陌生,有什么不对的地方很抱歉......
上面的代码是我尝试执行的操作,但它只是在我运行代码时运行该函数,而不是在我按下Button 时运行。我收到ValueError: The message cannot be empty unless a file is provided
from telethon import TelegramClient, events, sync
from tkinter import *
api_id = xxxxx
api_hash = 'xxxxxx'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
root = Tk()
canvas = Canvas(root)
canvas.pack()
code_entry = Entry(canvas)
code_entry.pack()
async def main():
cpf = code_entry.get()
await client.send_message('ConsignadoBot', cpf)
with client:
client.loop.run_until_complete(main)
search_btn = Button(canvas, text='Consultar', command=main)
search_btn.pack()
root.mainloop()
【问题讨论】:
标签: python bots telegram telethon