我正在尝试使用Tkinter的Entry()函数将此模块集成到Tkinter。然而,在将其集成时,终端等待输入。没有终端的输入,聊天将不会在GUI Tkinter输入窗口上进行。
我认为这是由“ sockets_list = [sys.stdin,套接字]”中的“ sys.stdin”引起的。我不知道用什么来代替sys.stdin for GUI。请帮忙谢谢!
def get_chat_entry(player, packet, lobby_id, connectPacket, event=None):
# maintains a list of possible input streams
sockets_list = [sys.stdin, socket]
#Instantiate chat packet
chatPacket = packet.ChatPacket()
read_sockets,write_socket,error_socket = select.select([socket],[],[])
for socks in read_sockets:
if socks == socket:
packet_received = bytearray(socket.recv(2048))
packet.ParseFromString(packet_received)
packet_type = packet.type
#Chat packet type
if packet_type == 3:
#Receive broadcasted data from server
chatPacket.ParseFromString(packet_received)
print(chatPacket.message)
#update chat_text_box
chat_history_Txt.config(state=NORMAL)
chat_history_Txt.insert(END, chatPacket.message + '\n')
chat_history_Txt.see("end")
chat_history_Txt.config(state=DISABLED)
else:
# #Write your message here
chatPacket.type = TcpPacket.CHAT
chatPacket.message = chat_entry.get()
socket.send(chatPacket.SerializeToString())