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 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("<Button-1>",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("<Key-Return>", self.enter)
|
||||
self.fenetre.bind("<Key-Escape>", 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()])
|
||||
self.value.set("")
|
||||
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 = {}
|
||||
|
Loading…
Reference in New Issue
Block a user