python - Issue with showing and updating image in Tkinter -
i'm able display image if grab 1 location, need image update along related article website. if open application tomorrow, different image appear. needless say, i'm using regular expressions image won't show on label. here's code far:
from tkinter import * import tkinter tk import re re import findall urllib import urlopen import datetime pil import image pil import image, imagetk cstringio import stringio root = tk() root.title("science , technology") root.geometry("600x600") main_label = label(root, text = "science , technology") main_label.pack() all_image_height = 400 all_image_width = 400 dash = "-" = datetime.datetime.now() text_area = labelframe(root, borderwidth = 2) text_area.pack(padx = 10, pady = 10, expand = 1, fill= both) date = label(text_area) date.pack() content_t = label(text_area) content_t.pack() imag = label(text_area) imag.pack() def science_all(): sw_img = 300 sh_img = 300 webscience = urlopen(urlscience) html_code = webscience.read() webscience.close() titl = findall("'name'>(.+[a-za-z])</title>", html_code)[0] date1 = str(now.day),(dash),(now.month),(dash),(now.year) content_title = findall('itemprop="name">(.+[a-za-z])</h5>',html_code)[0] text_area.config(text = titl) date.config(text = date1) content_t.config(text = content_title) url2 = "http://www.wired.com/" im = urlopen(url2) html_code2 = im.read() im.close() global image_file global photo_image global imag imag2 = findall('<img src="(.*)">', html_code2) image_file = image.open(stringio(html_code2)) photo_image = imagetk.photoimage(image_file) imag.config(image=imag2) science = button(root, text="science", command = science_all) science.pack(side=left) urlscience = 'http://www.wired.com/' root.mainloop()
it works fine when using link 1 specific image website when regular expressions come it, that's gets difficult me. suggestions helpful. thanks.
Comments
Post a Comment