I'm trying to create a GUI Weather app within Python. However, I can't get the text to display nicely, since I am using a Canvas over the main window to display the text, and I can't seem to get the background to be transparent, rather just a solid color.
Anyone have a good way to deal with this problem?
from forecastiopy import *
from geopy.geocoders import Nominatim
from tkinter import *
from PIL import Image
geolocator = Nominatim(user_agent="josephs-application")
# address = input("\nPlease enter an address: ")
address = "Syracuse NY"
location = geolocator.geocode(address)
def city_state_country(coord):
location = geolocator.reverse(coord, exactly_one=True)
address = location.raw['address']
city = address.get('city', '')
state = address.get('state', '')
country = address.get('country', '')
return city, state, country
print(city_state_country("43.0481301, -76.1474244"))
try:
coordinates = [location.latitude, location.longitude]
except AttributeError:
print("\n[!] Address not found [!]")
fio = ForecastIO.ForecastIO(apikey,
units=ForecastIO.ForecastIO.UNITS_SI,
lang=ForecastIO.ForecastIO.LANG_ENGLISH,
latitude=coordinates[0], longitude=coordinates[1])
print('\nLatitude', fio.latitude, 'Longitude', fio.longitude)
print('Timezone', fio.timezone, 'Offset', fio.offset)
def convertToF(celcius):
return (celcius / 5) * 9 + 32
if fio.has_currently() is True:
currently = FIOCurrently.FIOCurrently(fio)
daily = FIODaily.FIODaily(fio)
mainWindow = Tk()
mainWindow.title("Weather App V.1")
mainWindow.grid()
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.master = master
pad = 3
self._geom = '200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth() - pad, master.winfo_screenheight() - pad))
master.bind('<Escape>', self.toggle_geom)
def toggle_geom(self, event):
geom = self.master.winfo_geometry()
print(geom, self._geom)
self.master.geometry(self._geom)
self._geom = geom
app = FullScreenApp(mainWindow)
canvas = Canvas(mainWindow, bg="darkgray", height=1920, width=1080)
filename = PhotoImage(file="images/bg.png")
background_label = Label(mainWindow, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
canvas.grid()
topLeft = Frame(mainWindow)
topLeft.place(x=40, y=25, anchor="nw")
# topLeftCanvas = Canvas(topLeft, width=300, height=200)
# topLeftCanvas.create_image(100, 50, image=imageFile)
# topLeftCanvas.create_text(100, 50, text="Hello")
# topLeftCanvas.grid()
summaryLabel = Label(topLeft, text=currently.summary)
summaryLabel.config(font=("Verdana", 30))
summaryLabel.grid(row=1)
tempLabel = Label(topLeft, text=str(round(convertToF(currently.temperature), 2)) + "F")
tempLabel.config(font=("Verdana", 30))
tempLabel.grid(row=2)
#TODO: UGLY!! HARDCODED VALUE, FIX!
topRight = Frame(mainWindow)
topRight.place(x=1600, y=25, anchor="nw")
humidityLabel = Label(topRight, text=(str("Humidity\n" + str(currently.humidity) + "%")))
humidityLabel.config(font=("Verdana", 30))
humidityLabel.grid(row=1)
airPressureLabel = Label(topRight, text=(str("Air Pressure\n" + str(currently.pressure) + " ps")))
airPressureLabel.config(font=("Verdana", 30))
airPressureLabel.grid(row=2)
windSpeedLabel = Label(topRight, text=(str("Wind Speed\n" + str(currently.windSpeed) + " mph")))
windSpeedLabel.config(font=("Verdana", 30))
windSpeedLabel.grid(row=3)
mainWindow.mainloop()