Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather App by GPT-4 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions WeatherApp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tkinter as tk
import requests

def get_weather():
city = city_entry.get()
api_key = "YOUR_API_KEY" # جایگزین با کلید API خود
url = f'http://api.weatherapi.com/v1/current.json?key={WEATHER_KEY}&q={weather}&aqi=no'
response = requests.get(url)
data = response.json()

if response.status_code == 200:
weather = f"City: {data['name']}\nTemperature: {data['main']['temp']}°C\nWeather: {data['weather'][0]['description']}"
result_label.config(text=weather)
else:
result_label.config(text="City not found!")

# ایجاد پنجره اصلی
root = tk.Tk()
root.title("Weather App")

# ورودی شهر
city_label = tk.Label(root, text="Enter City:")
city_label.pack(pady=5)

city_entry = tk.Entry(root)
city_entry.pack(pady=5)

# دکمه برای دریافت آب و هوا
get_weather_button = tk.Button(root, text="Get Weather", command=get_weather)
get_weather_button.pack(pady=10)

# نمایش نتیجه
result_label = tk.Label(root, text="")
result_label.pack(pady=20)

# اجرای حلقه اصلی
root.mainloop()
Loading