Novice just learning a few days, do not spray! Not a lot of things, there is no comprehensive study related documents, resources and hope to share with you! Overall difficult.
A source code
. 1 Import itchat 2 Import Requests . 3 Import Tkinter . 4 from Tkinter Import MessageBox . 5 . 6 . 7 DEF FUNC (Self): . 8 CONT = text2.get (1.0, ' End ' ) .replace ( ' \ n- ' , '' ) . 9 IF len (CONT) == 0: 10 messagebox.showinfo ( " error " , " not send empty message " ) . 11 return 12 else: 13 try: 14 req = requests.get('http://i.itpk.cn/api.php', params={'question': cont}) 15 text1.config(state='normal') 16 text1.insert(tkinter.INSERT, '我: ' + cont + '\n') 17 text1.config(state='disabled') 18 text2.delete('1.0', ' End ' ) . 19 text1.config (State = ' Normal ' ) 20 is text1.insert (tkinter.INSERT, ' Xia Li: ' + req.text + ' \ n- ' ) 21 is text1.config (State = ' Disabled ' ) 22 is the except : 23 is messagebox.showinfo ( " error " , " transmission failed " ) 24 return 25 26 is 27 DEF enterkeyfunc(event): 28 if event.keycode == 13: 29 func(event) 30 31 32 def mouseenterfunc(event): 33 button1['bg'] = 'green' 34 35 36 def mouseleavefunc(event): 37 button1['bg'] = 'white' 38 39 40 win = tkinter.Tk() 41 win.title("机器人夏莉") 42 # Width x height + 400+ longitudinal lateral distance to the screen 100 43 is win.geometry ( " 400x500 + 400 + 100 " ) 44 is # prohibited maximized 45 win.wm_resizable (False, False) 46 is 47 text1 = tkinter.Text (win, height 26 is =, BG = ' # e6f1f1 ' ) 48 text2 = tkinter.Text (win, height =. 9, BG = ' White ' ) 49 Button1 = tkinter.Button (win, text = " send (S) " , width =. 8 , height =. 1 ) 50 51 is text1.pack (Anchor = tkinter.N) 52 is text2.pack (Anchor =tkinter.CENTER) 53 button1.pack(anchor=tkinter.SE) 54 text1.config(state='disabled') 55 56 text2.focus() 57 58 # 绑定事件 59 button1.bind("<Button-1>", func) 60 button1.bind("<Enter>", mouseenterfunc) 61 button1.bind("<Leave>", mouseleavefunc) 62 text2.bind("<Key>", enterkeyfunc) 63 64 win.mainloop ()
Second, the results: