From 1c184d5f338b1c85bf8b1226b3f7d05151144b0d Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 18 Aug 2018 15:31:37 +0200 Subject: [PATCH] ajout lien hypertext interface graphique --- chaineTV.py | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/chaineTV.py b/chaineTV.py index 9fa76f6..49090c3 100644 --- a/chaineTV.py +++ b/chaineTV.py @@ -3,9 +3,20 @@ import json import sys import os import unicodedata +from bs4 import BeautifulSoup +import webbrowser + +class Labbelink (Label): + + def __init__(self,parent,text,link): + Label.__init__(self,parent,text=text,fg="blue",cursor="hand2") + self.link=link + self.bind("",self._openlink) + + def _openlink(self,event): + webbrowser.open(self.link) class Interface: - import webbrowser def __init__(self): @@ -17,7 +28,7 @@ class Interface: self.label = Label(self.fenetre, text="entrer numero de chaine") self.entree = Entry(self.fenetre, textvariable=self.value, width=30) self.frame = Frame(self.fenetre) - self.label2 = Label(self.fenetre, text="") + self.resultframe = Frame(self.fenetre) self.bouton_update_base = Button( self.fenetre, text="update la base de chaine", command=self.click_update) self.bouton = Button(self.frame, text="OK", command=self.click) @@ -25,10 +36,10 @@ class Interface: self.label.pack() self.entree.pack() self.entree.focus_set() + self.resultframe.pack() self.frame.pack() self.bouton.pack(side=LEFT) self.reset.pack(side=RIGHT) - self.label2.pack() self.bouton_update_base.pack() self.fenetre.bind("", self.enter) self.fenetre.bind("", self.eventreset) @@ -45,28 +56,38 @@ class Interface: def click(self): print(self.value.get()) + labellink = Label(self.resultframe, text="") + try: - self.label2["text"] += self.data[self.value.get()]+"\r" + link= Labbelink(self.resultframe,self.data[self.value.get()],geturlprogrammetv(self.data[self.value.get()])) + link.pack() print(self.data[self.value.get()]) except KeyError: print("numero de chaine inconnue") - self.label2["text"] += "numero de chaine inconnue"+"\r" - self.value.set("") - return - self.label2["text"] += geturlprogrammetv(self.data[self.value.get()]) + unknow=Label(self.resultframe, text="numero de chaine inconnue") + unknow.pack() + + + + #self.label2["text"] += geturlprogrammetv(self.data[self.value.get()]) + self.value.set("") - def click_reset(self): print("reset") - self.fenetre.quit - self.label2["text"] = "" - self.fenetre.mainloop + for child in self.resultframe.winfo_children(): + child.destroy() + def click_update(self): parsechaine(self.datafilepath) self.data = load_jsonfile(self.datafilepath) - self.label2["text"] += "update chaine done"+"\r" + labelupdate = Label(self.resultframe, text="update chaine done"+"\r") + labelupdate.pack() + + def _openlink(self,link): + webbrowser.open_new(link) + @@ -88,9 +109,7 @@ def RepresentsInt(s): except TypeError: return False - def parsechaine(file): - from bs4 import BeautifulSoup import urllib.request URL = 'https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal' liste_chaine = {}