/
tkinter_demo.py
86 lines (67 loc) · 2 KB
/
tkinter_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# import everything from tkinter module
from tkinter import *
# globally declare the expression variable
expression = ""
import Tkinter, Tkconstants, tkFileDialog
from scrapper import Scrapper
FILE_NAME=None
SELENIUM=True
TEST=False
URL=None
sel_var=None
test_var=None
def browsefunc():
global FILE_NAME
filename = tkFileDialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
FILE_NAME=filename
def start_scraper():
global SELENIUM
global FILE_NAME
global TEST
kwargs ={
'selenium':SELENIUM,
'url':FILE_NAME,
'test':TEST ,
'skip_after':0,
'skip_before':0,
'export':'json'
}
if not TEST:
print('test not enabled...')
Scrapper(**kwargs).crawl()
else:
Scrapper.test()
# Driver code
if __name__ == "__main__":
# create a GUI window
gui = Tk()
global sel_var
global test_var
sel_var=IntVar()
test_var=IntVar()
def toggle_selenium():
global SELENIUM
SELENIUM = sel_var.get()
def toggle_test():
global TEST
TEST = test_var.get()
# set the title of GUI window
gui.title("Ops Expert Scraper Tool")
# set the configuration of GUI window
gui.geometry("500x300")
file_chooser = Button(gui, text=' Choose file to upload ', fg='black',
command=lambda: browsefunc(), height=1, width=7)
file_chooser.grid(row=2, column=1)
selenium_check = Checkbutton(gui, text='Selenium', fg='black',
command=lambda: toggle_selenium(), height=1, width=7,onvalue=True, offvalue=False, variable=sel_var)
selenium_check.grid(row=2, column=2)
test_run = Checkbutton(gui, text='Test Run !', fg='black',
command=lambda: toggle_test(),onvalue=True, offvalue=False, height=1, width=7,variable=test_var)
test_run.grid(row=2, column=3)
start_button = Button(gui, text='Start',command=lambda:start_scraper(), height=5,width=10)
start_button.grid(row=3,column=3)
skip_before = Entry(gui, bd =2)
skip_before.grid(row=4,column=3)
skip_after = Entry(gui, bd =2)
skip_after.grid(row=5,column=3)
gui.mainloop()