diff --git a/chaineTV.py b/chaineTV.py index c3e8b9a..b4cb3a6 100644 --- a/chaineTV.py +++ b/chaineTV.py @@ -8,7 +8,7 @@ import re import io from PIL import Image,ImageTk from bs4 import BeautifulSoup -from tkinter import Label,Button,Frame,Tk,Entry,StringVar,LEFT,RIGHT,PhotoImage,Image +from tkinter import Label,Button,Frame,Tk,Entry,StringVar,LEFT,RIGHT,PhotoImage,Image,Scrollbar,VERTICAL,Canvas,Y,BOTH,NW @@ -30,6 +30,40 @@ class LabelImage(Label): Label.__init__(self,parent,image=imagetoinsert) self.image = imagetoinsert + +class ScrollableCanvas(Frame): + def __init__(self, parent, *args, **kw): + Frame.__init__(self, parent, *args, **kw) + + canvas=Canvas(self,width=300,height=300,scrollregion=(0,0,500,500)) + + vbar=Scrollbar(self,orient=VERTICAL) + vbar.pack(side=RIGHT, fill=Y) + vbar.config(command=canvas.yview) + + canvas.config(width=200,height=200) + canvas.config(yscrollcommand=vbar.set) + canvas.pack(side=LEFT,expand=True,fill=BOTH) + + # create a frame inside the canvas which will be scrolled with it + self.interior = interior = Frame(canvas) + interior_id = canvas.create_window(0, 0, window=interior, anchor=NW ) + # track changes to the canvas and frame width and sync them, + # also updating the scrollbar + def _configure_interior(event): + # update the scrollbars to match the size of the inner frame + size = (interior.winfo_reqwidth(), interior.winfo_reqheight()) + canvas.config(scrollregion="0 0 %s %s" % size) + if interior.winfo_reqwidth() != canvas.winfo_width(): + # update the canvas's width to fit the inner frame + canvas.config(width=interior.winfo_reqwidth()) + interior.bind('', _configure_interior) + + def _configure_canvas(event): + if interior.winfo_reqwidth() != canvas.winfo_width(): + # update the inner frame's width to fill the canvas + canvas.itemconfigure(interior_id, width=canvas.winfo_width()) + canvas.bind('', _configure_canvas) class Interface: def __init__(self): @@ -41,9 +75,8 @@ 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.resultframe = Frame(self.fenetre) - self.bouton_update_base = Button( - self.fenetre, text="update la base de chaine", command=self.click_update) + self.resultframe = ScrollableCanvas(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) self.reset = Button(self.frame, text="reset", command=self.click_reset) self.label.pack() @@ -72,36 +105,37 @@ class Interface: try: strlink=geturlprogrammetv(self.data[self.value.get()]) - link= Labbelink(self.resultframe,self.data[self.value.get()],strlink) + link= Labbelink(self.resultframe.interior,self.data[self.value.get()],strlink) link.pack() - print(self.data[self.value.get()]) self.resultframe.update() + print(self.data[self.value.get()]) + emision=parse_emmission(strlink) if emision: if emision == "can't find show": - Label(self.resultframe,text="impssible de parser cette chaine").pack() + Label(self.resultframe.interior,text="impssible de parser cette chaine").pack() else: - image=LabelImage(self.resultframe,emision['img']) + image=LabelImage(self.resultframe.interior,emision['img']) image.pack() - Labbelink(self.resultframe,("emmision ce soir: "+emision["title"]),emision['href']).pack() + Labbelink(self.resultframe.interior,("emmision ce soir: "+emision["title"]),emision['href']).pack() if len(emision['casting']) > 0: - Label(self.resultframe,text="réalisateur: "+emision['casting'][0]).pack() - Label(self.resultframe,text="acteur: "+str(emision['casting'][1:])).pack() - Label(self.resultframe,text="synopsys: " +emision['synopsis'],wraplength=350).pack() + Label(self.resultframe.interior,text="réalisateur: "+emision['casting'][0]).pack() + Label(self.resultframe.interior,text="acteur: "+str(emision['casting'][1:])).pack() + Label(self.resultframe.interior,text="synopsys: " +emision['synopsis'],wraplength=350).pack() else: - Label(self.resultframe,text="pas de connection internet impossible de determiner l'émission du soir").pack() + Label(self.resultframe.interior,text="pas de connection internet impossible de determiner l'émission du soir").pack() except KeyError: print("numero de chaine inconnue") - unknow=Label(self.resultframe, text="numero de chaine inconnue") + unknow=Label(self.resultframe.interior, text="numero de chaine inconnue") unknow.pack() self.value.set("") - + def click_reset(self): print("reset") - for child in self.resultframe.winfo_children(): + for child in self.resultframe.interior.winfo_children(): child.destroy() @@ -236,6 +270,4 @@ if len(sys.argv) > 1: else: cli(i) else: - Interface().mainloop() - - + Interface().mainloop() \ No newline at end of file