I wrote a script that uploads all images from an given page URL to my imgur account and prints the output. It works fine, but now one of my non-technical friends wants too use the app but he does not want to use the command line, so I tried to make an GUI.
I am a newbie to GUI making. I made something that should take an input from the GUI, pass the input to a function and output the urls uploaded (urls in my imgur account).
My program calls the function fine. urls get converted but the window stops responding but the program is running.
but after the first function completes the window starts responding again
then i can print the converted urls
Here is the code:
from bs4 import BeautifulSoup
from Tkinter import *
import Tkinter as tk
import requests, pyimgur, time
from urlparse import urljoin
urllist = []
def callback():
global urllist
for i in urllist:
tex.insert(tk.END, i + '\n')
tex.see(tk.END)
def connection(url):
#global urllist
print '\n\n', url, '\n\n'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
urllist = parse(soup, url)
def parse(parsed, url):
global urllist
client_id = 'myid'
image_links = [i.get('src') for i in parsed.find_all("img")]
for u in image_links:
if u.split('.')[-1] == 'jpg':
try:
time.sleep(1)
im = pyimgur.Imgur(client_id)
uploaded_image = im.upload_image(url=urljoin(url, '%20'.join(u.split(' '))), title="shady")
#printing the uploaded image links
print uploaded_image.link
#calling the function to output in the gui
urllist.append(uploaded_image.link)
except Exception as e:
print e
#return urllist
#url = raw_input("Enter the url")
#url = 'https://www.oceanreefresorts.com/beaches-south-walton-rentals/adagio'
#connection(url)
root = Tk()
tex = tk.Text(master=root)
tex.pack(side=tk.RIGHT)
root.config(height = 360, width = 640)
root.title('Url Conversion App')
root.resizable(False, False)
firstName = StringVar()
userAge = IntVar()
tk.Label(root, text = 'URL: ').place(x=20, y=300)
tk.Entry(root, width = 30, textvariable = firstName).place(x=115, y=300)
convertimages = tk.Button(root, text = 'CONVERT', command= lambda: connection(firstName.get())).place(x=20, y=350)
buttonTestPrint = tk.Button(root, text = 'print', command=callback).place(x=20, y=320)
root.update()
root.mainloop()