Найти - Пользователи
Полная версия: TKINTER для клиент сервера
Начало » GUI » TKINTER для клиент сервера
1
Artem.Churbakov
Ребят помогите с GUI для программы,есть программка клиент-сервер,надо чтобы сообщения с клиента на сервер и обратно отсылались по нажатию на кнопку,а сам текст сообщения высвечивался что там что там в отдельном окне,вот сам кривой код,помогите плизз,а то что то вообще не могу разобраться((
СЕРВЕР
#-*- coding: utf-8 -*-
from socket import *
from Tkinter import *
 
root = Tk()
root.title('Сервер')
root.geometry("200x200+80+80")
 
btn = Button(root,text='Отправить')
btn.place(x=70,y=60)
 
string = Entry(root,width = 10)
string.place(x = 70,y = 40)
 
 
 
HOST = ''
PORT = 8000
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', 8000))
s.listen(1)
conn, addr = s.accept()
print 'Соединенно ', addr
 
 
 
 
 
 
def send(event):
    i = True
    while i is True:
        data = conn.recv(1024)
        print 'Пришло ', repr(data)
        reply = string.get()
        #reply = raw_input("Ответ: ")
        conn.sendall(reply)
        ppp = Label(root,font = "Arial 11",text = reply,width =20,)
        ppp.place(x = 10,y =170)
    root.destroy()
 
btn.bind('<ButtonRelease-1>', send)
root.mainloop()
 
 
conn.close()

КЛИЕНТ
# -*- coding: utf-8 -*-
from socket import *
from Tkinter import *
 
root = Tk()
root.title('Клиент')
root.geometry("200x200+80+80")
 
btn = Button(root,text='Отправить')
btn.place(x=70,y=60)
 
string = Entry(root,width = 10)
string.place(x = 70,y = 40)
 
 
HOST = ''
PORT = 8000
s = socket(AF_INET, SOCK_STREAM)
s.connect((HOST, PORT))
def send(event):
    i = True
    while i is True:
        message = string.get()
        #message = raw_input("Ваше сообщение: ")
        s.send(message)
        print "Ждите ответа"
        reply = s.recv(1024)
end send(event)
def otvet(event):
    print "Ответ: ", repr(reply)
    ppp = Label(root,font = "Arial 11",text = reply,width =20,)
    ppp.place(x = 10,y =170)
    root.destroy()
 
 
#root.bind('<Control-z>',quit)
btn.bind('<ButtonRelease-1>', send)
root.mainloop()
s.close()
4kpt
Поконкретней. Что имеется ввиду, когда Вы говорите: “В новом окне”?

P.S. У Вас не очень хорошо реализована сама технология передачи данных. Рекомендую почитать Бизли Д. Python - подробный справочник. стр. 586-606 :)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB