修改代码使其通过分帧的方式实现动图的发送和显示#发送表情的函数 def send_mark(exp): ''' :param exp: 表情图片对应的标识符 :return: ''' global ee mes = exp +':;'+user+':;'+chat_to s.send(mes.encode()) b1.destroy() b2.destroy() b3.destroy() b4.destroy() b5.destroy() b6.destroy() ee = 0 #四种表情包的标识符发送函数 def bb1(): send_mark('aa**') def bb2(): send_mark('bb**') def bb3(): send_mark('cc**') def bb4(): send_mark('dd**') def bb5(): send_mark('ff**') def bb6(): send_mark('gg**') #表情包面包操控函数 def express_board(): global b1,b2,b3,b4,b5,b6,ee if ee == 0: #打开表情包面板 ee = 1 b1 = tkinter.Button(root,command=bb1,image=p1,relief=tkinter.FLAT,bd=0) b2 = tkinter.Button(root,command=bb2,image=p2,relief=tkinter.FLAT,bd=0) b3 = tkinter.Button(root,command=bb3,image=p3,relief=tkinter.FLAT,bd=0) b4 = tkinter.Button(root,command=bb4,image=p4,relief=tkinter.FLAT,bd=0) b5 = tkinter.Button(root,command=bb5,image=p5,relief=tkinter.FLAT,bd=0) b6 = tkinter.Button(root, command=bb6,image=p6,relief=tkinter.FLAT,bd=0) b1.place(x=5,y=248) b2.place(x=75,y=248) b3.place(x=145, y=248) b4.place(x=215, y=248) b5.place(x=285, y=248) b6.place(x=445, y=248) else: #关闭表情包面板 ee = 0 b1.destroy() b2.destroy() b3.destroy() b4.destroy() b5.destroy() b6.destroy() #表情包面板开关按钮 eBut = tkinter.Button(root,text='表情包',command=express_board) eBut.place(x=5,y=320,width=60,height=30)
时间: 2024-02-09 14:10:16 浏览: 105
tsne的matlab代码-hyperspectral_exp_orz:hyperspectral_exp_orz
要通过分帧的方式实现动图的发送和显示,需要修改代码中的发送函数和接收函数。以下是一个修改后的代码示例:
```
#发送表情的函数
def send_mark(exp):
'''
:param exp: 表情图片对应的标识符
:return:
'''
global ee
mes = exp + ':;' + user + ':;' + chat_to
s.send(mes.encode())
b1.destroy()
b2.destroy()
b3.destroy()
b4.destroy()
b5.destroy()
b6.destroy()
ee = 0
#发送表情包的函数
def send_gif(filename):
'''
:param filename: GIF文件名
:return:
'''
# 加载GIF文件
im = Image.open(filename)
# 分帧
frames = []
for frame in ImageSequence.Iterator(im):
frames.append(frame.copy())
# 连接到网络
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 12345))
# 发送分帧数据
for frame in frames:
# 将帧转换为bytes对象
data = frame.tobytes()
# 发送帧数据
sock.sendall(data)
# 等待一段时间,以实现动画效果
time.sleep(0.1)
# 关闭网络连接
sock.close()
#四种表情包的标识符发送函数
def bb1():
send_mark('aa**')
send_gif('example1.gif')
def bb2():
send_mark('bb**')
send_gif('example2.gif')
def bb3():
send_mark('cc**')
send_gif('example3.gif')
def bb4():
send_mark('dd**')
send_gif('example4.gif')
def bb5():
send_mark('ff**')
send_gif('example5.gif')
def bb6():
send_mark('gg**')
send_gif('example6.gif')
#表情包面板控制函数
def express_board():
global b1, b2, b3, b4, b5, b6, ee
if ee == 0: #打开表情包面板
ee = 1
b1 = tkinter.Button(root, command=bb1, relief=tkinter.FLAT,
阅读全文