-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNoticia.py
41 lines (36 loc) · 1.5 KB
/
Noticia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from tkinter.ttk import Progressbar
import PIL.Image
import PIL.ImageTk
from io import BytesIO
from urllib.request import urlopen
from tkinter import *
class Noticia (Frame):
def __init__(self, parent, titulo, url, image) -> None:
Frame.__init__(self, parent, highlightbackground="blue", highlightthickness=2)
Frame.__init__(self, parent, highlightbackground="blue", highlightthickness=2, width=350, height=90)
self._image_url = image
if (not self._image_url.startswith('http')):
self._image_url = "https:" + self._image_url
self._title = titulo
self.url = url
if (not self.url.startswith('http')):
self.url = "https:" + self.url
self._create_frame()
def _create_frame(self):
self._create_thumb()
self._create_title()
def _create_thumb(self):
try:
with urlopen(self._image_url) as url:
_raw = url.read()
url.close()
image = PIL.Image.open(BytesIO(_raw)).resize((160,90))
except:
image = PIL.Image.open("not_found.png").resize((160,90))
self._photo_image = PIL.ImageTk.PhotoImage(image)
self._image = Label(self, image=self._photo_image)
self._image.pack()
self._image.pack(side=LEFT, padx=5, anchor="w")
def _create_title(self):
self._title = Label(self, text=self._title, font=("Calibri",10), justify=LEFT, wraplength=290, anchor="w")
self._title.pack(side=TOP, padx=(0,5), fill="x")