我怎样才能进行多次聊天

时间:2015-12-11 00:43:06

标签: python python-2.7

好的,我需要一些帮助....我有一个tkinter聊天程序的基本代码。我需要帮助让我的客户在文本字段中更新。我试图在tkinter窗口中运行messages2()代码,但由于server.recv()块,它会暂停我的程序,所以我必须在main函数内的函数中运行它。但我必须先调用该函数才能显示任何内容。我能做些什么来解决这个问题,这是我为这个项目做的最后一件事。

def chat1():
    global rmessages
    global nmessages
    global messages
    global root4
    nmessages=""
    rmessages=""

    def messages():
        global nmessages
        global newmess
        global messagebox


        rmessages = (messagesend.get('1.0', 'end-1c'))
        server.send(rmessages)
        newmess = server.recv(BUFFERSIZE)
        nmessages =  nmessages + "\n" + newmess
        messagebox = Text(root4, height = 30 , width = 65, yscrollcommand=scrollbar.set, wrap = WORD)
        messagebox.insert(index=1.0, chars= nmessages)
        messagebox.config(state = DISABLED)
        messagebox.place(x = 10, y = 10)
        scrollbar.config(command=messagebox.yview)
        print newmess

    root4 = Tk()
    root4.title("Chat")
    root4.geometry("600x600")
    scrollbar = Scrollbar(root4)
    scrollbar.pack( side = RIGHT, fill=Y )

    menubar = Menu(root4)
    filemenu = Menu(menubar, tearoff = 0)
    filemenu.add_command(label="Exit", command=root4.destroy)
    menubar.add_cascade(label="File", menu=filemenu)
    about1 = Menu(menubar, tearoff=0)
    about1.add_command(label="About", command=about)
    menubar.add_cascade(label="About", menu=about1)
    log = Menu(menubar, tearoff=0)
    log.add_command(label="Logoff", command=clientwin)
    menubar.add_cascade(label="Logoff", menu=log)
    messagesend = Text(root4, width = 60, height = 3, wrap = WORD)
    messagesend.place(x = 10, y = 530)
    sendbutton1= Button(root4, text = "Send", bg = "white", command = messages)
    sendbutton1.place(x = 530, y = 525)
    root4.config(menu=menubar)
    root4.mainloop()

0 个答案:

没有答案