NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import tkinter as tk
from tkinter import ttk, messagebox
import requests

# OpenWeatherMap API
API_KEY = "bb8306c119de14cfbc40137c5e13f0de"
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"

# List of 81 cities in Turkey"
cities = [
"Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Aksaray", "Amasya", "Ankara", "Antalya", "Ardahan", "Artvin",
"Aydın", "Balıkesir", "Bartın", "Batman", "Bayburt", "Bilecik", "Bingöl", "Bitlis", "Bolu", "Burdur",
"Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli", "Diyarbakır", "Düzce", "Edirne", "Elazığ", "Erzincan",
"Erzurum", "Eskişehir", "Gaziantep", "Giresun", "Gümüşhane", "Hakkâri", "Hatay", "Iğdır", "Isparta", "İstanbul",
"İzmir", "Kahramanmaraş", "Karabük", "Karaman", "Kars", "Kastamonu", "Kayseri", "Kırıkkale", "Kırklareli", "Kırşehir",
"Kilis", "Kocaeli", "Konya", "Kütahya", "Malatya", "Manisa", "Mardin", "Mersin", "Muğla", "Muş",
"Nevşehir", "Niğde", "Ordu", "Osmaniye", "Rize", "Sakarya", "Samsun", "Şanlıurfa", "Siirt", "Sinop",
"Sivas", "Şırnak", "Tekirdağ", "Tokat", "Trabzon", "Tunceli", "Uşak", "Van", "Yalova", "Yozgat",
"Zonguldak", "Kürdistan" # Adding "Kürdistan" to the list
]

def get_weather(city):
if city == "Kürdistan":
messagebox.showerror("Hata", "Böyle bir yer yok salak mısın?")
return

try:
# Send Request to API
params = {
'q': city,
'appid': API_KEY,
'units': 'metric', # For Celsius
'lang': 'tr' # For Turkish language
}
response = requests.get(BASE_URL, params=params)
data = response.json()

# Check if API Request is Successful
if response.status_code == 200:
main = data.get('main')
weather = data.get('weather', [{}])[0]
wind = data.get('wind', {})
temp = main.get('temp')
feels_like = main.get('feels_like')
humidity = main.get('humidity')
description = weather.get('description', 'No description available')
wind_speed = wind.get('speed', 'No wind speed available')

# Weather Condition
weather_info = (
f"n{city} Hava Durumu:n"
f"Sıcaklık: {temp}°Cn"
f"Hissedilen Sıcaklık: {feels_like}°Cn"
f"Nem: {humidity}%n"
f"Rüzgar Hızı: {wind_speed} m/sn"
f"Açıklama: {description.capitalize()}"
)
messagebox.showinfo("Hava Durumu", weather_info)
else:
# Unknown Error for API
messagebox.showerror("Hata", f"Şehir bulunamadı: {city}nHata kodu: {response.status_code}nHata mesajı: {data.get('message', 'Unknown Error')}")
except requests.exceptions.RequestException as e:
messagebox.showerror("Hata", f"API isteği sırasında bir hata oluştu: {e}")

def main():
def on_submit():
city = city_var.get()
if city:
get_weather(city)
else:
messagebox.showerror("Hata", "Lütfen bir şehir seçin.")

root = tk.Tk()
root.title("Hava Durumu Uygulaması")

main_frame = ttk.Frame(root, padding="10")
main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))

ttk.Label(main_frame, text="Hava Durumunu Öğrenmek İstediğiniz Şehri Seçin:").grid(row=0, column=0, pady=10)

city_var = tk.StringVar()
city_dropdown = ttk.Combobox(main_frame, textvariable=city_var)
city_dropdown['values'] = cities
city_dropdown.grid(row=1, column=0, pady=10)

submit_button = ttk.Button(main_frame, text="Hava Durumunu Göster", command=on_submit)
submit_button.grid(row=2, column=0, pady=10)

root.mainloop()

if __name__ == "__main__":
main()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.