我正在尝试编写一个Python 3.x程序,用于访问网站上的数据(图片,文本等)。我还想在Tkinter GUI中显示该数据。
BTW,我在Windows上使用Python 3.4。
答案 0 :(得分:1)
尝试使用urllib
下载并使用Pillow
PIL
分叉来处理图片:
from Tkinter import *
from PIL import ImageTk
import urllib
# initialize window
root = Tk()
root.geometry('640x480')
# retrieve and download image
location = 'https://www.python.org/static/community_logos/python-logo.png'
image = open('image.png', 'wb')
image.write(urllib.urlopen(location).read())
image.close()
# create canvas for drawing
canvas = Canvas(root, width = 640, height = 480)
canvas.place_configure(x = 0, y = 0, width = 640, height = 480)
# load image with PIL and draw to canvas
image = ImageTk.PhotoImage(file = 'image.png')
canvas.create_image(10, 10, image = image, anchor = NW)
# start program
root.mainloop()
答案 1 :(得分:-2)
https://pypi.python.org/pypi/wget
试试wget!这是一个简单的网络刮刀,可以做你想要的。