话不多说 上代码
第一步
// An highlighted block
class Talkr(object): #定义个类 初始化
def __init__(self):
self.config_1()
pass
第二步 画出主页面
def config_1(self):
self.window = Tk()
self.window.minsize(300, 300)
self.window.title('帮助')
#self.window.geometry('300x300')
self.request = Text(self.window, background='light cyan')
self.request.place(x=10, y=210, width=280, height=30)
self.title_label1 = Label(self.window, text=u'text: (text)')
self.title_label1.place(x=8, y=185)
self.responses = Text(self.window, background='light cyan')
self.responses.place(x=10, y=5, width=280, height=180)
self.submit1 = Button(self.window, text=u'text' ,command=self.help)
self.submit1.place(x=245, y=245, width=45, height=45)
self.submit2 = Button(self.window, text=u'text' ,command=self.clean)
self.submit2.place(x=195, y=245, width=45, height=45)
第三步 添加功能
def _quit(self):
self.window.quit()
self.window.destroy()
def talk(self,talk):
try:
res = requests.post("http://api.qingyunke.com/api.php?key=free&appid=0&msg=" + talk) #自动回复接口!!
res = res.json()
tlk1 = str("robot:{} ".format(res["content"]))
self.responses.insert(END, str("{0:{2}<0}n{1:{2}<0}".format(tlk1, '', chr(12288))))
except:
pass
def help(self):
talk = self.request.get(0.0, END).strip().replace("n", " ")
if talk == 'text':
self.responses.delete(0.0, END)
self.responses.insert(END,'text')
else:
self.talk(talk)
def clean(self):
self.request.delete(0.0, END)
self.responses.delete(0.0, END)
def run(self):
self.window.mainloop()
Demo :
完整代码 https://pan.baidu.com/s/14e-dT7LRgIDoxg68YgVOKA
key :1234



