【发布时间】:2020-11-09 12:18:55
【问题描述】:
我写了一个可以运行的代码,我想把我的程序变成一个 GUI 程序。 每当我运行程序时,我都会收到此错误:
C:\Users\Mohamad Bilal\AppData\Local\Programs\Python\Python39\lib\threading.py:888: RuntimeWarning: coroutine 'start_sending' was never awaited
self._target(*self._args, **self._kwargs)
这是我的代码:
import openpyxl as xl
import os
from telethon import TelegramClient
import tkinter as tk
from tkinter import filedialog
import threading
root = tk.Tk()
canvas = tk.Canvas(root, height=500, width=500, bg='#263D42')
canvas.pack()
frame = tk.Frame(root, bg='white')
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
load_excel = tk.Button(root, text='Load Excel', padx=10, pady=5, fg='white', bg='#263D42', command=load_excel)
product_count_txt = tk.Entry(root)
product_count_txt.insert(0, '1')
channel = tk.Entry(root, )
channel.insert(0, 'mohammadbelal')
product_count_txt.pack()
channel.pack()
load_excel.pack()
wb = xl.load_workbook('new.xlsx')
sheet = wb['Sheet1']
api_id =
api_hash = ''
token = ''
phone = ''
client = TelegramClient('session', api_id, api_hash)
async def start_sending():
await client.connect()
if not client.is_user_authorized():
await client.send_code_request(phone)
await client.sign_in(phone, input('Enter the code: '))
pp = await product_count_txt.get()
product_count = int(pp)
receiver = await channel.get()
for i in range(product_count):
s = i + 2
d = await sheet.cell(s, 3)
price = await sheet.cell(s, 27)
seri = await sheet.cell(s, 43)
sku = await d.value
size = await sheet.cell(s, 7)
message = f'''<b>Package (Seri) :</b> {seri.value} Pcs
<b>Size:</b> {size.value[343:-350]}
</br>
<b>Price:</b> {price.value} $
<b>Code:</b> {sku}
<b>Whatsapp for more info:</b>
????+90 541 841 66 36
<b><a href="https://www.facebook.com/istabuyGCC/">Facebook</a> |
<a href="https://www.instagram.com/istabuy/">Instagram</a> | istabuy.com®</b>
'''
image = []
for folder, subs, files in os.walk('images\\' + sku):
for filename in files:
if filename.endswith(".jpg"):
await image.append(os.path.abspath(os.path.join(folder, filename)))
await client.send_file(receiver, image)
await client.send_message(receiver, message, parse_mode='html', link_preview=False)
print(sku, 'Has been Sent!')
start_sending_btn = tk.Button(root, text='Start Sending', padx=10, pady=5, fg='white', bg='#263D42',
command=threading.Thread(target=start_sending).start())
start_sending_btn.pack()
root.mainloop()
【问题讨论】:
-
请参阅this example,了解如何将 Telethon 与 tkinter 集成
标签: python-3.x tkinter telethon