Answer the question
In order to leave comments, you need to log in
Why does the script show only one picture?
Hello!
The script should show about 50 pictures, and then it shows one empty Label.
Here is the actual script
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()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question