This code basically takes 2 user inputs as string & later use them to form URL
After i run this code , The TK window hangs up(freezes) if (if or elif) condition is False, here is the code .
Somebody please help on the same. Please see below code.
#!/usr/bin/env python
from Tkinter import *
import requests, csv, time, json, tkFileDialog
from lxml import html, etree
from tkFileDialog import askopenfilename
def countdown(p,q):
i=p
j=q
k=0
while True:
if(j==-1):
j=59
i-=1
if(j > 9):
print "\r"+str(k)+str(i)+":"+str(j),
else:
print "\r"+str(k)+str(i)+":"+str(k)+str(j),
time.sleep(1)
j -= 1
if(i==0 and j==-1):
break
if(i==0 and j==-1):
print "\rGoodbye!"
time.sleep(1)
links = []
root = Tk()
root.geometry('300x130')
label1 = Label( root, text="Please Enter Search Term")
E1 = Entry(root, bd =5)
label2 = Label( root, text="Please enter City")
E2 = Entry(root, bd =5)
def quit(self):
self.root.destroy()
def getData():
a = 'try again'
global Search_string, City
Search_string = E1.get();
City = E2.get();
if Search_string == '':
print 'Please enter [mandatory field] Search Term - (%s)' % a
print 'Program will exit in 10 seconds'
countdown(0,10)
sys.exit()
elif City == '':
print 'Please enter [mandatory field] City also - (%s)' % a
print 'Program will exit in 10 seconds'
countdown(0,10)
sys.exit()
else:
print Search_string,'\n',City
root.destroy()
submit = Button(root, text ="Submit", command = getData)
label1.pack()
E1.pack()
label2.pack()
E2.pack()
submit.pack(side=BOTTOM)
mainloop()
Search_string = Search_string.replace(' ','+')
partial_link_1 = ("https://www.google.com/search?q=");partial_link_2 = '&num=10'
Tk().withdraw()
csvfile = tkFileDialog.asksaveasfile(mode='w', defaultextension=".csv")
i = 0
while i < 40:
url = partial_link_1+Search_string+'+'+'in'+'+'+City+partial_link_2+'&start='+str(i)
i+=10
links.append(url)
for i in links: print "Links = %r"%i