You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
6 months ago
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
from Connexion import Connexion
|
||
|
import tkinter as tk
|
||
|
|
||
|
|
||
|
class Interface(tk.Tk):
|
||
|
"""interface graphique pour envoyer/recevoir/chiffrer/dechiffrer"""
|
||
|
def __init__(self, sens):
|
||
|
tk.Tk.__init__(self)
|
||
|
self.connexion = Connexion(sens)
|
||
|
self.title(sens)
|
||
|
self.entree = tk.StringVar()
|
||
|
tk.Entry(self, textvariable=self.entree, width=30).pack()
|
||
|
tk.Label(text="Message reçu : ").pack()
|
||
|
self.message = tk.StringVar()
|
||
|
tk.Label(textvariable=self.message).pack()
|
||
|
self.sendButton = tk.Button(self, text="Send", command=self.send)
|
||
|
self.sendButton.pack()
|
||
|
self.recvButton = tk.Button(self, text="Receive", command=self.receive)
|
||
|
self.recvButton.pack()
|
||
|
|
||
|
def send(self):
|
||
|
"""Envoie le message chiffré."""
|
||
|
message = self.entree.get().encode("utf8")
|
||
|
# à compléter pour chiffrer le message
|
||
|
self.connexion.send(message)
|
||
|
|
||
|
def receive(self):
|
||
|
"""Réceptionne un message depuis le serveur et l'affiche.
|
||
|
Attention : bloque tant que le serveur n'envoie rien."""
|
||
|
message = self.connexion.recv()
|
||
|
# à compléter pour déchiffrer le message
|
||
|
self.message.set(message.decode("utf8"))
|
||
|
|
||
|
def destroy(self):
|
||
|
self.connexion.close()
|
||
|
tk.Tk.destroy(self)
|