I want a function that, when a button is clicked, it will take an image from the web using URLLIB and display it in a GUI using TKINTER.
I'm new to both URLLIB and TKINTER, so I'm having an incredibly difficult time doing this.
Tried this, but it obviously doesn't work because it uses a textbox and only will display text.
def __init__(self, root):
self.root = root
self.root.title('Image Retrieval Program')
self.init_widgets()
def init_widgets(self):
self.btn = ttk.Button(self.root, command=self.get_url, text='Get Url', width=8)
self.btn.grid(column=0, row=0, sticky='w')
self.entry = ttk.Entry(self.root, width=60)
self.entry.grid(column=0, row=0, sticky='e')
self.txt = tkinter.Text(self.root, width=80, height=20)
self.txt.grid(column=0, row=1, sticky='nwes')
sb = ttk.Scrollbar(command=self.txt.yview, orient='vertical')
sb.grid(column=1, row=1, sticky='ns')
self.txt['yscrollcommand'] = sb.set
def get_url(self):
s = urllib.request.urlretrieve("http://www.smellymonkey.com/monkeys/images/ill-monkey.gif", "dog.gif")
tkimage = ImageTk.PhotoImage(im)
self.txt.insert(tkinter.INSERT, s)