代码
'''
按send后又延时,请注意
'''
import tkinter as tk
import time
import urllib.request
import urllib.parse
import requests
def Text():
time_me = ('我:' + time.strftime('%Y-%m-%d %H:%M:%S') + '\n')
time_Emma = ('Emma:' + time.strftime('%Y-%m-%d %H:%M:%S') + '\n') # , time.localtime()
ask = msg.get()
msg.delete(0, 'end')
disp.insert("end", time_me) # 获取发送消息,添加文本到消息列表
disp.insert("end", ask + "\n")
url = 'http://api.qingyunke.com/api.php?key=free&appid=0&msg={}'.format(urllib.parse.quote(ask))
html = requests.get(url)
res = html.json()["content"]
disp.insert("end", time_Emma)
disp.insert("end", res + "\n\n---------------->>\n")
rec = disp.get("0.0", "end")
def Event(event): # 绑定enter键
if event.keysym == 'Return':
Text()
win = tk.Tk()
win.title('Emma-AI')
win.geometry('600x371')
win.iconbitmap('fa.ico') # 请将图标放于程序同目录下
tk.Label(win, text='消息记录框:').pack()
disp = tk.Text(win, width=600, height=20)
disp.pack() # 文本输入框
tk.Label(win, text='消息输入框:').pack()
msg = tk.Entry(win, width=600) # 内容输入框
msg.pack()
msg.bind('<KeyPress-Return>', Event)
# 发送
btnRead = tk.Button(win, height=1, width=10, text="Send", command=Text).pack()
win.mainloop()
附件
评论