-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_window.py
81 lines (63 loc) · 2.61 KB
/
main_window.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
"""This module contains view and logic of main window"""
from tkinter import BooleanVar
from tkinter import Button
from tkinter import Checkbutton
from tkinter import Entry
from tkinter import Frame
from tkinter import Label
from tkinter import StringVar
from tkinter import Tk
import tkinter.messagebox as msg
from browser import Browser
class MainWindow():
"""Main GUI window class"""
def __init__(self):
root = Tk()
root.geometry("800x150")
root.title("Code Friend")
self.search = StringVar()
self.search.set("")
frame = Frame(root, borderwidth=5)
frame.grid(row=0, column=3)
search_label = Label(frame, text="Enter What you want to search",
font="Helvetica 15 bold", fg="blue")
search_label.grid(row=0, column=4)
search_textbox = Entry(frame, textvar=self.search,
font="lucida 15 italic")
search_textbox.grid(row=0, column=5)
self.use_google = BooleanVar()
google = Checkbutton(text="Google", variable=self.use_google)
google.grid(row=1, column=3)
self.use_youtube = BooleanVar()
yt_checkbutton = Checkbutton(text="Youtube", variable=self.use_youtube)
yt_checkbutton.grid(row=2, column=3)
self.use_stackoverflow = BooleanVar()
so_checkbutton = Checkbutton(text="Stack Overflow",
variable=self.use_stackoverflow)
so_checkbutton.grid(row=3, column=3)
self.use_github = BooleanVar()
gh_checkbutton = Checkbutton(text="Github", variable=self.use_github)
gh_checkbutton.grid(row=4, column=3)
search_button = Button(frame, text="Search", font="lucida 15 italic")
search_button.bind("<Button-1>", self.search_button_clicked)
search_button.grid(row=0, column=6)
root.mainloop()
def search_button_clicked(self, event):
"""Handler of Search Button"""
google = self.use_google.get()
youtube = self.use_youtube.get()
stackoverflow = self.use_stackoverflow.get()
github = self.use_github.get()
if any([google, youtube, stackoverflow, github]):
browser = Browser()
request = self.search.get()
if google:
browser.search_google(request)
if youtube:
browser.search_youtube(request)
if stackoverflow:
browser.search_stackoverflow(request)
if github:
browser.search_github(request)
else:
msg.showerror("Error", "Please Select a option first!")