您好! 我试图通过使用此代码将图像显示在标签上
这是为了保存来自特定网址的随机图片
def photo_1():
urls = "https://www.flickr.com/photos/flickr/galleries/72157644537473411/" # You may change this into other websites!
regex = '<img src="([^"]+)".*>'
pattern = re.compile(regex)
photofile=urllib.urlopen(urls)
raw_data=photofile.read()
download=re.findall(pattern,raw_data)
randomdownload=random.choice(download)
urllib.urlretrieve(randomdownload, "1.gif")
global done_button2
done_button2 = Button(photo_window, text = 'Click here to display your chosen image on the black screen!', width = 53, command = generate_1)
done_button2.grid(row = 5, sticky = N)
done_button.config(state='disabled')
这是为了让保存的图像出现在标签上,但显然效果不佳......
def generate_1():
img = ImageTk.PhotoImage(Image.open("1.gif"))
image_area = Label(photo_window, image = img, width = 55, height = 5).grid(row=2)
global done_button3
done_button3 = Button(photo_window, text = 'Click here to save the second random image locally! ', width = 53, command = photo_2)
done_button3.grid(row = 6, sticky = N)
done_button2.config(state='disabled')
这是我的代码的一部分,当我运行这个应用程序时,
我唯一可以看到的是一个白色的矩形形状,我希望它与下面的黑色标签一样大(尺寸为(55,5)),实际图像出现......
任何人都可以帮我解决这个问题吗? 你可能认为我的英语不是那么好哈哈 但请怜悯!