Всем привет!Скрипт должен показать около 50 картинок а показывает одну потом пустой LabelВот собственно скриптimport io
from time import sleep
from threading import Thread
from tkinter import Tk, Canvas, Label, Button, BOTTOM, CENTER, mainloop
from PIL import Image, ImageTk
import requests
from bs4 import BeautifulSoup
class Application(Tk):
url_images = "http://bipbap.ru/pictures/prikolnye-kartinki-pro-programmistov-55-foto.html"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36\
(KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7'}
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.geometry('800x600+300+100')
self.title('Просмотр картинок из интернета не сохраняя на диск')
self.resizable(width=False, height=False)
self.button = Button(self, text = 'начать просмотр', command = self.run)
self.button.pack(side = BOTTOM)
self.thread = Thread(target=self.image_upload)
def run(self):
self.thread.start()
self.button.config(state='disabled')
def image_upload(self):
response = requests.get(self.url_images, headers=self.headers)
soup = BeautifulSoup(response.content, 'lxml')
links_image = []
for link in soup.find_all('img'):
links_image.append((link.get('src')))
for link_image in links_image:
response = requests.get(link_image, headers=self.headers)
bytes_content = io.BytesIO(response.content)
image = Image.open(bytes_content)
w, h = image.size
image_tk = ImageTk.PhotoImage(image)
panel = Label(self, image=image_tk, justify=CENTER)
panel.config(width=w, height=h)
panel.pack(fill="both", expand="no")
if __name__ == "__main__":
application = Application()
application.mainloop()