-
Notifications
You must be signed in to change notification settings - Fork 5
/
gui.py
92 lines (87 loc) · 3.73 KB
/
gui.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
87
88
89
90
91
92
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 13 02:17:24 2017
@author: SuperKogito
"""
# Define imports
import tkinter as tk
from scrape import Scraper
from tkinter import ttk, Label, Entry, LabelFrame
class MainWindow(tk.Tk):
""" Main window class """
def __init__(self, title):
super().__init__()
xyla = [0, 0, 1270, 80]
self.ext = ''
self.original_path = ''
self.title(title)
self.minsize(xyla[2], xyla[3])
#self.resizable(0, 0)
self.configure(background='black')
self.geometry("%dx%d+%d+%d" % (xyla[0], xyla[1], 400, 100))
# Define bind events
self.bind("<Escape>", self.quit_func)
# Define colors
colors = ["#0080ff", "white", "black"]
# Define style
ttk.Style().configure("TNotebook", background=colors[2])
ttk.Style().map("TNotebook.Tab",
background=[("selected", colors[0])],
foreground=[("selected", colors[1])])
self.option_add("*Font", "courier")
# Define input section frames
self.frame = LabelFrame(self, text="", bg="black", fg='white')
self.label_frame = tk.Frame(self.frame, bg="black")
self.input_frame = tk.Frame(self.frame, bg="black")
# Pack widgets
self.frame.pack(expand=1, fill="both", padx=5, pady=5)
self.label_frame.pack(expand=1, fill="both", padx=5, pady=2)
self.input_frame.pack(expand=1, fill="both", padx=10, pady=2)
# Set label widget up
self.label = Label(self.label_frame, bg="black", fg='white',
text='Coinmarketcap historical data URL to scrape from: (example:https://coinmarketcap.com/currencies/bitcoin/historical-data/...)')
self.entry = Entry(self.input_frame, width=110)
self.label.pack(side=tk.LEFT)
self.entry.pack(side=tk.LEFT)
# Set button widget up
b2 = tk.Button(self.input_frame, text='Scrape', command=self.get_input)
b2.pack(side=tk.RIGHT, pady=5)
b2.configure(background="black", foreground='white',
activebackground='#0080ff', activeforeground='white')
# Create menu and call mainloop
self.create_menu()
self.mainloop()
def create_menu(self):
self.menu = tk.Menu(self, tearoff=False)
# Menu item File
self.filemenu = tk.Menu(self.menu, tearoff=0)
self.menu.add_cascade(label="File", underline=0, menu=self.filemenu)
self.filemenu.add_command(label="Exit", underline=2,
command=self.quit_func, accelerator="Esc")
# Menu item Edit
self.editmenu = tk.Menu(self.menu, tearoff=0)
self.menu.add_cascade(label="Edit", underline=0, menu=self.editmenu)
self.editmenu.add_command(label="Clear", underline=2,
command=self.edit_clear)
# Coloring the menu
for menu_element in (self.filemenu, self.editmenu):
menu_element.configure(bg='black', fg='white',
activebackground='#0080ff',
activeforeground='white')
self.config(menu=self.menu)
self.menu.configure(background='black', foreground='white',
activebackground='#0080ff',
activeforeground='white')
def quit_func(self, event=None):
self.destroy()
# Edit menu functions
def edit_clear(self, event=None):
self.entry.delete(0, 'end')
def get_input(self):
self.url = self.entry.get()
print('Scraping from: ', self.url)
scraper = Scraper()
data = scraper.process(self.url)
scraper.write_to_csv(data)
print('Done.')
return