300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > tkinter + wxpy 实现微信发送信息 接收消息 并保存聊天记录的功能(GUI)

tkinter + wxpy 实现微信发送信息 接收消息 并保存聊天记录的功能(GUI)

时间:2020-10-03 22:59:42

相关推荐

tkinter + wxpy 实现微信发送信息 接收消息 并保存聊天记录的功能(GUI)

'''导入相关库'''import tkinter #界面库from wxpy import * #微信库def loginWeChat():'''Function:登录微信'''global botbot = Bot() #初始化微信,会显示登录二维码界面def logoutWeChat():'''Function:登出微信'''bot.logout()chatform.destroy()#关闭窗口def addFriendListToTable():'''Function:添加好友到好友列表框当中'''bot.friends(update=False) #更新好友列表friend_list = bot.friends(False).search() #得到好友列表 type:<class 'wxpy.api.chats.chats.Chats'>for i in range(2): #显示前10位经常联系的好友user_detail_info = bot.user_details(friend_list[i], 50) #获得好友信息friend_info = str(user_detail_info)listbox_friends.insert(i,friend_info)@bot.register(Friend, TEXT)def showMessageInfo(msg):listbox_ReceiveMsg.insert(tkinter.END, str(msg))if listbox_ReceiveMsg.size() >= 10:listbox_ReceiveMsg.delete(0,tkinter.END)def sendMessageToFriend():'''Function:发送消息给好友'''select_friendname = txt_Sender.get(0.0,tkinter.END)check_friend = bot.friends().search(select_friendname)[0]send_msg = txt_SendMsg.get(0.0,tkinter.END)check_friend.send(send_msg)sent_msgs = bot.messages.search(sender=bot.self) #获得自己发送的消息current_sent_msgs = str(sent_msgs[len(sent_msgs)-1])listbox_ReceiveMsg.insert(tkinter.END,current_sent_msgs)txt_SendMsg.delete(0.0,tkinter.END) #发送完信息后清空if listbox_ReceiveMsg.size() >= 10: #清空listBoxlistbox_ReceiveMsg.delete(0, tkinter.END)def autoReplyInfo():'''Function:自动回复信息功能'''@bot.register(Friend,PICTURE)def replyInfoFormal(msg):return "I am busy!"'''初始化界面及相关参数'''chatform = tkinter.Tk()chatform.geometry("500x700") #设置窗体大小 width x heightchatform.resizable(width=False,height=False) #设置大小不可变chatform.title("YTouch微信聊天") #标题'''添加相关控件'''#登录微信按钮btn_login = tkinter.Button(text='登录微信',command=loginWeChat)btn_login['fg'] = 'red' #字体颜色btn_login['bg'] = 'blue' #背景色btn_login.place(x = 220,y = 600,width = 60,height = 30) #x:距离左半边的距离,y:距离上面的距离#退出微信按钮btn_logout = tkinter.Button(text='退出微信',command=logoutWeChat)btn_logout['fg'] = 'red' #字体颜色btn_logout['bg'] = 'blue' #背景色btn_logout.place(x = 300,y = 600,width = 60,height = 30) #x:距离左半边的距离,y:距离上面的距离#更新好友列表按钮btn_FriendList = tkinter.Button(text='更新好友',command=addFriendListToTable)btn_FriendList['fg'] = 'red' #字体颜色btn_FriendList['bg'] = 'blue' #背景色btn_FriendList.place(x =0 ,y = 0,width = 60,height = 30) #x:距离左半边的距离,y:距离上面的距离#发送消息按钮btn_SendMsg = tkinter.Button(text='发送消息',command=sendMessageToFriend)btn_SendMsg['fg'] = 'red' #字体颜色btn_SendMsg['bg'] = 'blue' #背景色btn_SendMsg.place(x =400 ,y = 600,width = 60,height = 30) #x:距离左半边的距离,y:距离上面的距离#自动回复按钮btn_ReplyAuto = tkinter.Button(text='自动回复',command=autoReplyInfo)btn_ReplyAuto['fg'] = 'red' #字体颜色btn_ReplyAuto['bg'] = 'blue' #背景色btn_ReplyAuto.place(x = 120,y = 600,width = 60,height = 30) #x:距离左半边的距离,#输入消息文本框txt_SendMsg = tkinter.Text(chatform,height = 1) #height表示几行txt_SendMsg.place(x =200 ,y = 500,width = 260)#选择指定好友文本框txt_Sender = tkinter.Text(chatform,height = 1) #height表示几行txt_Sender.place(x =0 ,y = 500,width = 150)#消息对话框listbox_ReceiveMsg = tkinter.Listbox(chatform) #height表示几行listbox_ReceiveMsg.place(x =240,y = 50,width =200,height = 300)#好友列表框listbox_friends = tkinter.Listbox(chatform,height = 300)listbox_friends.place(x = 20,y = 50,width = 200,height = 300)chatform.mainloop() #保持登录状态

界面显示:

现在还差做个数据库

后期再完善图片视频的显示

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。