Skip to content

Commit a72b59d

Browse files
committed
Fixed flake8 documentation styling
To remain consistent, I ran flake8 linting on the USWeatherForecast.py app and corrected as needed. Flake8 now runs with no errors.
1 parent 2bb667f commit a72b59d

File tree

1 file changed

+60
-47
lines changed

1 file changed

+60
-47
lines changed
Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from tkinter import *
2-
from tkinter import ttk
1+
import tkinter as tk
2+
import tkinter.ttk as ttk
33
import requests
44

55
# Free Open Weather API (https://rapidapi.com/community/api/open-weather-map/)
@@ -11,100 +11,113 @@
1111
}
1212

1313
# initialize tkinter GUI
14-
root = Tk()
15-
16-
weather_frame = Frame(root)
14+
root = tk.Tk()
15+
weather_frame = tk.Frame(root)
1716
weather_frame.grid(columnspan=3, row=3)
1817
weather_view = ttk.Treeview(weather_frame)
1918

19+
2020
# Initialize table for US city weather information
2121
def createTable(data, city):
22-
weather_view['columns'] = ('city', 'temperature', 'minTemp', 'maxTemp', 'condition', 'description')
23-
weather_view.column("#0", width=0, stretch=NO)
24-
weather_view.column("city",anchor=CENTER, width=85)
25-
weather_view.column("temperature",anchor=CENTER,width=95)
26-
weather_view.column("minTemp",anchor=CENTER,width=75)
27-
weather_view.column("maxTemp",anchor=CENTER,width=75)
28-
weather_view.column("condition",anchor=CENTER,width=75)
29-
weather_view.column("description",anchor=CENTER,width=95)
30-
31-
weather_view.heading("#0",text="",anchor=CENTER)
32-
weather_view.heading("city",text="City Name",anchor=CENTER)
33-
weather_view.heading("temperature",text="Temperature (F)",anchor=CENTER)
34-
weather_view.heading("minTemp",text="Min Temp",anchor=CENTER)
35-
weather_view.heading("maxTemp",text="Max Temp",anchor=CENTER)
36-
weather_view.heading("condition",text="Condition",anchor=CENTER)
37-
weather_view.heading("description",text="Description",anchor=CENTER)
22+
weather_view['columns'] = ('city', 'temperature',
23+
'minTemp', 'maxTemp',
24+
'condition', 'description')
25+
weather_view.column("#0", width=0, stretch=tk.NO)
26+
weather_view.column("city", anchor=tk.CENTER, width=85)
27+
weather_view.column("temperature", anchor=tk.CENTER, width=95)
28+
weather_view.column("minTemp", anchor=tk.CENTER, width=75)
29+
weather_view.column("maxTemp", anchor=tk.CENTER, width=75)
30+
weather_view.column("condition", anchor=tk.CENTER, width=75)
31+
weather_view.column("description", anchor=tk.CENTER, width=95)
32+
33+
weather_view.heading("#0", text="", anchor=tk.CENTER)
34+
weather_view.heading("city", text="City Name", anchor=tk.CENTER)
35+
weather_view.heading("temperature", text="Temperature (F)",
36+
anchor=tk.CENTER)
37+
weather_view.heading("minTemp", text="Min Temp", anchor=tk.CENTER)
38+
weather_view.heading("maxTemp", text="Max Temp", anchor=tk.CENTER)
39+
weather_view.heading("condition", text="Condition", anchor=tk.CENTER)
40+
weather_view.heading("description", text="Description", anchor=tk.CENTER)
3841
NewEntry(data, city)
3942

43+
4044
# Populate table with weather information for each new US city
4145
def NewEntry(data, city):
4246
try:
43-
temp = str(round((((int(data['list'][1]['main']['temp']) - 273.15) * 1.8) + 32), 2))
44-
temp_min = str(round((((int(data['list'][1]['main']['temp_min']) - 273.15) * 1.8) + 32), 2))
45-
temp_max = str(round((((int(data['list'][1]['main']['temp_max']) - 273.15) * 1.8) + 32), 2))
47+
temp = str(round((((int(data['list'][1]['main']['temp'])
48+
- 273.15) * 1.8) + 32), 2))
49+
temp_min = str(round((((int(data['list'][1]['main']['temp_min'])
50+
- 273.15) * 1.8) + 32), 2))
51+
temp_max = str(round((((int(data['list'][1]['main']['temp_max'])
52+
- 273.15) * 1.8) + 32), 2))
4653
weather = data['list'][2]['weather'][0]['main']
4754
weather_desc = data['list'][2]['weather'][0]['description']
48-
49-
weather_view.insert(parent='',index='end',iid=None,text='',
50-
values=(city, temp, temp_min, temp_max, weather, weather_desc))
55+
weather_view.insert(parent='', index='end', iid=None, text='',
56+
values=(city, temp, temp_min, temp_max,
57+
weather, weather_desc))
5158
weather_view.grid(columnspan=3, row=3)
52-
53-
except:
54-
weather_view.insert(parent='',index='end',iid=None,text='',
55-
values=(city, None, None, None, None, None))
59+
except Exception:
60+
weather_view.insert(parent='', index='end', iid=None, text='',
61+
values=(city, None, None, None, None, None))
5662
weather_view.grid(columnspan=3, row=3)
5763

5864

5965
root.title("US Weather Tracker")
6066

61-
canvas = Canvas(root, width=600, height=120)
67+
canvas = tk.Canvas(root, width=600, height=120)
6268
canvas.grid(columnspan=3, rowspan=5)
6369

6470
# Weather Tracker application - title
65-
label = Label(root, text="US Weather Tracker")
71+
label = tk.Label(root, text="US Weather Tracker")
6672
label.grid(columnspan=3, row=0, pady=30)
6773
label.configure(font=("Courier", 25, "bold"), fg='#092653')
6874

6975
# Weather Tracker application - title
70-
desc = Label(root, text="Provide a US city name below...")
76+
desc = tk.Label(root, text="Provide a US city name below...")
7177
desc.grid(columnspan=3, row=1, pady=10)
7278
desc.configure(font=("Courier", 10))
7379

7480
# Prompts the user to enter a city
75-
cityLabel = Label(text="City Name:")
81+
cityLabel = tk.Label(text="City Name:")
7682
cityLabel.grid(column=0, row=2, pady=20)
7783
cityLabel.configure(font=("Courier", 16))
7884

79-
cityEntry = Entry(root, width=50, borderwidth = 2)
85+
cityEntry = tk.Entry(root, width=50, borderwidth=2)
8086
cityEntry.grid(column=1, row=2, pady=20)
8187

8288
# Global variables to update button text and check if table exists
8389
newTable = True
84-
button_text = StringVar()
85-
button_text.set("Get Weather");
90+
button_text = tk.StringVar()
91+
button_text.set("Get Weather")
92+
8693

8794
# Function to add a new city to the list of weather forecasts
8895
def addWeather():
8996
global newTable
90-
if newTable == True:
97+
if newTable:
9198
city = cityEntry.get()
9299
location = city + ",us"
93-
querystring = {"q":location}
94-
response = requests.request("GET", url, headers=headers, params=querystring)
100+
querystring = {"q": location}
101+
response = requests.request("GET", url, headers=headers,
102+
params=querystring)
95103
createTable(response.json(), city)
96-
button_text.set("Add New City");
104+
button_text.set("Add New City")
97105
newTable = False
98-
elif newTable == False:
106+
elif not newTable:
99107
city = cityEntry.get()
100108
location = city + ",us"
101-
querystring = {"q":location}
102-
response = requests.request("GET", url, headers=headers, params=querystring)
109+
querystring = {"q": location}
110+
response = requests.request("GET", url, headers=headers,
111+
params=querystring)
103112
NewEntry(response.json(), city)
104113

114+
105115
# Button to add cities to weather forecast table
106-
getCityWeather = Button(root, textvariable=button_text, command=addWeather, width = 30,
107-
font=("Courier", 15), bg='#092653', fg="white").grid(columnspan=3, row=4, pady=10)
116+
getCityWeather = tk.Button(root, textvariable=button_text,
117+
command=addWeather, width=30,
118+
font=("Courier", 15),
119+
bg='#092653',
120+
fg="white").grid(columnspan=3, row=4, pady=10)
108121

109122

110123
root.mainloop()

0 commit comments

Comments
 (0)