Created
October 1, 2022 16:01
-
-
Save Alexandro1112/976b800beb71ac75bea4f74987f94e79 to your computer and use it in GitHub Desktop.
Awsome wather meneger in Tkinter window~!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
import time | |
from tkinter import * | |
import pyowm | |
from pyowm.commons import exceptions | |
tk = Tk('Weather-Meneger') | |
while True: | |
try: | |
from OWMTOKENs import token | |
except ModuleNotFoundError: | |
print(f'Sing up in https://openweathermap.org and getting API key!') | |
break | |
def button_press(): | |
text = '' | |
input['text'] = input.get().lower() | |
text += input['text'] | |
if input['text'] != '': | |
try: | |
owm = pyowm.OWM(token) | |
mgr = owm.weather_manager() | |
observation = mgr.weather_at_place(input['text']) | |
ready_wether = observation.weather | |
w = observation.weather | |
cel = ready_wether.temperature('celsius') | |
feels_like = cel['feels_like'] | |
max_temp = cel['temp_max'] | |
min_temp = cel['temp_min'] | |
humidity = ready_wether.humidity | |
windy = w.wind()['speed'] | |
clouds = w.clouds | |
temperature = Label(tk,text=f' Погода в городе - {input["text"]} \n' | |
f'---------------------------------------------- \n' | |
f' {input["text"] - observation} \n' | |
f' Погода ощущается как {round(feels_like)}°С \n' | |
f' Максимальная температура {round(max_temp)}°С \n' | |
f' Минимальная температура {round(min_temp)}°С \n' | |
f' Температура прямо сейчас {round(cel["temp"])}°С\n' | |
f' Влажность-{round(humidity)} %\n' | |
f' Скорость ветра-{round(windy)}м/с \n' | |
f' Количество облаков-{round(clouds)}%' | |
, fg='gold', bg='SteelBlue4', width=300, height=8, borderwidth=2, font=("Arial Bold", 17)) | |
temperature.pack(fill=BOTH,anchor=SW,ipadx=4,ipady=4,side='top') | |
def remove(): | |
temperature.pack_forget() | |
return temperature | |
b2 = Button(tk, text='Скрыть результат поиска', command=remove, | |
font=200, fg='yellow', bg='gold', | |
foreground='gold', background='yellow') | |
b2.pack(fill=BOTH,pady=2,padx=2) | |
def show(): | |
temperature.pack() | |
return temperature | |
b3 = Button(tk, text='Показать результат поиска', command=show, font=200, fg='yellow', bg='gold', | |
foreground='gold', background='yellow') | |
b3.pack(fill=BOTH, pady=2, padx=2) | |
except exceptions.NotFoundError or exceptions.APIRequestError or exceptions.ParseAPIResponseError: | |
response_error = Label(tk, text='\nПожайлуста , введите верное название города!\n', | |
background='gold',fg='gold',bg='SteelBlue4', borderwidth=2, font=("Arial Bold", 17)) | |
response_error.pack(anchor=NW,fill=BOTH) | |
void2 = Label(tk, font=('times', 20, 'bold'), bg='SteelBlue') | |
void2.pack(fill=BOTH, anchor=NW) | |
else: | |
void_error = Label(tk, text='\nПожайлуста ,введите хотя бы что-то !\n', fg='gold', | |
bg='SteelBlue4', borderwidth=2, font=("Arial Bold", 17)) | |
void_error.pack(anchor=NW, fill=BOTH) | |
tk.clipboard_append(string='weather') | |
canvas = Canvas(tk,width=5,height=0,bg='gold',background='gold') | |
canvas.pack() | |
tk.geometry('400x1200') | |
tk['bg'] = 'SteelBlue' | |
b1 = Button(tk, text='Узнать погоду в регионе', command=button_press, font=200, bg='gold2', underline=True, | |
foreground='gold', background='yellow', activeforeground='gold', activebackground='gold',) | |
b1.pack(padx=4,pady=4) | |
input = Entry(tk, width=20, background='gold', font=("Arial Bold", 26),selectborderwidth=3) | |
input.pack(anchor=NW, pady=6, padx=4) | |
if __name__ == '__main__': | |
time.sleep(0.5) | |
quit(mainloop()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment