ajout lien hypertext interface graphique
This commit is contained in:
parent
c5af0e55e0
commit
1c184d5f33
49
chaineTV.py
49
chaineTV.py
@ -3,9 +3,20 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import unicodedata
|
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("<Button-1>",self._openlink)
|
||||||
|
|
||||||
|
def _openlink(self,event):
|
||||||
|
webbrowser.open(self.link)
|
||||||
|
|
||||||
class Interface:
|
class Interface:
|
||||||
import webbrowser
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -17,7 +28,7 @@ class Interface:
|
|||||||
self.label = Label(self.fenetre, text="entrer numero de chaine")
|
self.label = Label(self.fenetre, text="entrer numero de chaine")
|
||||||
self.entree = Entry(self.fenetre, textvariable=self.value, width=30)
|
self.entree = Entry(self.fenetre, textvariable=self.value, width=30)
|
||||||
self.frame = Frame(self.fenetre)
|
self.frame = Frame(self.fenetre)
|
||||||
self.label2 = Label(self.fenetre, text="")
|
self.resultframe = Frame(self.fenetre)
|
||||||
self.bouton_update_base = Button(
|
self.bouton_update_base = Button(
|
||||||
self.fenetre, text="update la base de chaine", command=self.click_update)
|
self.fenetre, text="update la base de chaine", command=self.click_update)
|
||||||
self.bouton = Button(self.frame, text="OK", command=self.click)
|
self.bouton = Button(self.frame, text="OK", command=self.click)
|
||||||
@ -25,10 +36,10 @@ class Interface:
|
|||||||
self.label.pack()
|
self.label.pack()
|
||||||
self.entree.pack()
|
self.entree.pack()
|
||||||
self.entree.focus_set()
|
self.entree.focus_set()
|
||||||
|
self.resultframe.pack()
|
||||||
self.frame.pack()
|
self.frame.pack()
|
||||||
self.bouton.pack(side=LEFT)
|
self.bouton.pack(side=LEFT)
|
||||||
self.reset.pack(side=RIGHT)
|
self.reset.pack(side=RIGHT)
|
||||||
self.label2.pack()
|
|
||||||
self.bouton_update_base.pack()
|
self.bouton_update_base.pack()
|
||||||
self.fenetre.bind("<Key-Return>", self.enter)
|
self.fenetre.bind("<Key-Return>", self.enter)
|
||||||
self.fenetre.bind("<Key-Escape>", self.eventreset)
|
self.fenetre.bind("<Key-Escape>", self.eventreset)
|
||||||
@ -45,28 +56,38 @@ class Interface:
|
|||||||
|
|
||||||
def click(self):
|
def click(self):
|
||||||
print(self.value.get())
|
print(self.value.get())
|
||||||
|
labellink = Label(self.resultframe, text="")
|
||||||
|
|
||||||
try:
|
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()])
|
print(self.data[self.value.get()])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("numero de chaine inconnue")
|
print("numero de chaine inconnue")
|
||||||
self.label2["text"] += "numero de chaine inconnue"+"\r"
|
unknow=Label(self.resultframe, text="numero de chaine inconnue")
|
||||||
self.value.set("")
|
unknow.pack()
|
||||||
return
|
|
||||||
self.label2["text"] += geturlprogrammetv(self.data[self.value.get()])
|
|
||||||
self.value.set("")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#self.label2["text"] += geturlprogrammetv(self.data[self.value.get()])
|
||||||
|
|
||||||
|
self.value.set("")
|
||||||
|
|
||||||
def click_reset(self):
|
def click_reset(self):
|
||||||
print("reset")
|
print("reset")
|
||||||
self.fenetre.quit
|
for child in self.resultframe.winfo_children():
|
||||||
self.label2["text"] = ""
|
child.destroy()
|
||||||
self.fenetre.mainloop
|
|
||||||
|
|
||||||
def click_update(self):
|
def click_update(self):
|
||||||
parsechaine(self.datafilepath)
|
parsechaine(self.datafilepath)
|
||||||
self.data = load_jsonfile(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:
|
except TypeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def parsechaine(file):
|
def parsechaine(file):
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
URL = 'https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal'
|
URL = 'https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal'
|
||||||
liste_chaine = {}
|
liste_chaine = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user