Skip to content

Commit 748161f

Browse files
committed
Improved grid layout and commented the whole thing
1 parent 40fb3c7 commit 748161f

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

gnewsclient/GUI/GUI.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from tkinter import ttk
55

66

7+
# function to set attributes(language, location, topic), and then fetch news accordingly
8+
# we have variables topic_query, language_query, location_query for storing attributes
79
def news():
810
global location_query, language_query,topic_query,edition_query,client,status
9-
client.query=None
11+
client.query=None # because search query overrides all other parameters
1012
client.topic=topic_query.get()
1113
if(client.topic=="Select topic"):
1214
client.topic = "top stories"
@@ -29,14 +31,15 @@ def news():
2931
return
3032

3133

34+
# to search news related to a search string
3235
def search():
3336
global search_query,client,status
3437
client.query= search_query.get()
3538
update_status(client,status)
3639
print(client.get_news())
3740
return
3841

39-
42+
# helper function for status bar
4043
def getstatus(clientX):
4144
x = clientX.get_config()
4245
y=sorted(x)
@@ -45,62 +48,68 @@ def getstatus(clientX):
4548
text += str(i) + ": " + str(x[i]) + " "
4649
return text
4750

51+
# set status bar text
4852
def update_status(client, status):
4953
status['text']=getstatus(client)
5054
return
5155

5256

5357

54-
58+
#initializing window
5559
root = Tk()
5660
root.title("GNEWSCLIENT")
5761

62+
#object making and packing
5863
client = gnewsclient()
5964
status = Label(root, text=getstatus(client), bd=1, relief=SUNKEN)
6065
status.pack(side=BOTTOM, fill=X)
6166

6267

63-
68+
# implementing searching news
6469
search_frame=Frame(root)
6570
search_frame.pack()
6671
search_query = StringVar()
6772
query = Entry(search_frame, textvariable=search_query).grid(row=1, column=0)
6873
search_button = Button(search_frame,text= "search", command=search).grid(row=1, column = 1)
6974

75+
west_frame = Frame(root)
76+
west_frame.pack(side=LEFT)
7077

7178

72-
tle_frame=Frame(root)
79+
# frame for topic, location, and edition filters
80+
tle_frame=Frame(west_frame)
7381
tle_frame.pack()
74-
edition_label = Label(tle_frame, text="Edition: ").grid(row=1, column=0)
82+
83+
# implementing edition filter
84+
edition_label = Label(tle_frame, text="Edition: ").grid(row=1, column=0,pady=50,sticky=W)
7585
edition_query=StringVar()
76-
edition_dropdown = ttk.Combobox(tle_frame, textvariable=edition_query, values=sorted(list(utils.editionMap))).grid(row=1, column=1)
86+
edition_dropdown = ttk.Combobox(tle_frame, textvariable=edition_query, values=sorted(list(utils.editionMap))).grid(row=1, column=1,pady=50)
7787
edition_query.set("Select edition")
7888

79-
80-
topic_label = Label(tle_frame, text="Topic: ").grid(row=2, column=0)
89+
# implementing topic filter
90+
topic_label = Label(tle_frame, text="Topic: ").grid(row=2, column=0,pady=50,sticky=W)
8191
topic_query=StringVar()
82-
topic_dropdown = ttk.Combobox(tle_frame, textvariable=topic_query, values=sorted(list(utils.topicMap))).grid(row=2, column=1)
92+
topic_dropdown = ttk.Combobox(tle_frame, textvariable=topic_query, values=sorted(list(utils.topicMap))).grid(row=2, column=1,pady=50)
8393
topic_query.set("Select topic")
8494

8595

86-
87-
language_label = Label(tle_frame, text="Language: ").grid(row=3, column=0)
96+
# implementing language filter
97+
language_label = Label(tle_frame, text="Language: ").grid(row=3, column=0,pady=50,sticky=W)
8898
language_query=StringVar()
89-
language_dropdown = ttk.Combobox(tle_frame, textvariable=language_query, values=sorted(list(utils.langMap))).grid(row=3, column=1)
99+
language_dropdown = ttk.Combobox(tle_frame, textvariable=language_query, values=sorted(list(utils.langMap))).grid(row=3, column=1,pady=50)
90100
language_query.set("Select language")
91101

92102

93103

94-
95-
location_label= Label(tle_frame,text="Location: ").grid(row=4,column=0)
104+
# implementing location filter
105+
location_label= Label(tle_frame,text="Location: ").grid(row=4,column=0,pady=50,sticky=W)
96106
location_query = StringVar()
97-
location = Entry(tle_frame, textvariable=location_query).grid(row=4, column=1)
98-
107+
location = Entry(tle_frame, textvariable=location_query).grid(row=4, column=1,pady=50)
99108

100109

101110

102-
getnews = Button(root, command=news,text = "Get News!")
103-
getnews.pack()
111+
# button to fetch news
112+
getnews = Button(tle_frame, command=news,text = "Get News!").grid(row=6,column=0,columnspan=2, pady=25)
104113

105114

106115

0 commit comments

Comments
 (0)