-
Notifications
You must be signed in to change notification settings - Fork 0
/
idojaras.py
184 lines (167 loc) · 8.31 KB
/
idojaras.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import requests
import json
import os
os.system('cls')
import time
import tkinter as tk
import random
import customtkinter
import tkintermapview
try:
window = customtkinter.CTk()
window.geometry("1000x650")
window.title("Időjárás")
window.resizable(0, 0)
label = customtkinter.CTkLabel(window, text="Írj be egy települést vagy országot", font=("Helvetica", 24))
#lat = 47.49
#lon = 19.34
api = "a3c3ac028697416ece9bd3c3a7c0f500"
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
"""def remover():
pass"""
def lightd():
customtkinter.set_appearance_mode("light")
customtkinter.set_default_color_theme("light")
text_entry = customtkinter.CTkEntry(master=window,
placeholder_text="Település / Ország",
width=200,
height=20,
font=("Helvetica", 18),
corner_radius=50,
text_color="green",
placeholder_text_color="lightblue",
fg_color=("blue", "darkblue"),
state="normal")
def dark():
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
"""light = customtkinter.CTkButton(master=window,
width=120,
height=32,
border_width=0,
corner_radius=10,
text="Világos",
hover_color="lightblue",
command=lightd)
light.place(relx=0.01, rely=0)"""
dark = customtkinter.CTkButton(master=window,
width=120,
height=32,
border_width=0,
corner_radius=10,
text="Sötét",
hover_color="lightblue",
command=dark)
dark.place(relx=0.14, rely=0)
text_entry = customtkinter.CTkEntry(master=window,
placeholder_text="Település / Ország",
width=200,
height=20,
font=("Helvetica", 18),
corner_radius=50,
text_color="green",
placeholder_text_color="darkblue",
fg_color=("blue", "lightblue"),
state="normal")
def submit_input():
varos = text_entry.get()
lekerdez = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={varos}&appid=a3c3ac028697416ece9bd3c3a7c0f500&units=metric')
jsonformatum = json.loads(lekerdez.text)
message = customtkinter.CTkLabel(window, text=f"Város: {jsonformatum['name']}", font=("Helvetica", 18))
void = tk.Label(window, text=f"")
tempareture = customtkinter.CTkLabel(window, text=f"A jelenlegi hőmérséklet: {jsonformatum['main']['temp']} °C", font=("Helvetica", 18))
tempareture_feels = customtkinter.CTkLabel(window, text=f"A jelenlegi hőérzet: {jsonformatum['main']['feels_like']} °C", font=("Helvetica", 18))
if jsonformatum['weather'][0]['description'] == "clear sky":
sky = customtkinter.CTkLabel(window, text=f"Az ég tiszta", font=("Helvetica", 18))
if jsonformatum['weather'][0]['description'] == "few clouds":
sky = customtkinter.CTkLabel(window, text=f"Néhány felhő van az égen", font=("Helvetica", 18))
else:
sky = customtkinter.CTkLabel(window, text=f"Az ég: {jsonformatum['weather'][0]['description']}", font=("Helvetica",18))
if jsonformatum['wind']['speed'] == 0:
wind = customtkinter.CTkLabel(window, text=f"Jelenleg nincs szél", font=("Helvetica", 18))
else:
wind = customtkinter.CTkLabel(window, text=f"A szél sebessége: {jsonformatum['wind']['speed']} m/s", font=("Helvetica", 18))
humadity = customtkinter.CTkLabel(window, text=f"A jelenlegi páratartartalom: {jsonformatum['main']['humidity']} %", font=("Helvetica", 18))
if jsonformatum['cod'] == 404:
print("Adj meg létező várost")
if KeyError == 'name':
print("Adj meg létező várost")
message.pack()
message.place(relx=0.1, rely=0.2)
#void.pack()
tempareture.pack()
tempareture.place(relx=0.1, rely=0.4)
tempareture_feels.pack()
tempareture_feels.place(relx=0.1, rely=0.5)
sky.pack()
sky.place(relx=0.1, rely=0.6)
wind.pack()
wind.place(relx=0.1, rely=0.7)
humadity.pack()
humadity.place(relx=0.1, rely=0.8)
def remover():
humadity.place_forget()
message.place_forget()
tempareture.place_forget()
tempareture_feels.place_forget()
sky.place_forget()
wind.place_forget()
humadity.place_forget()
hider.place_forget()
hider = customtkinter.CTkButton(master=window,
width=120,
height=32,
border_width=0,
corner_radius=10,
text="Eltüntetés",
hover_color="lightblue",
command=remover)
hider.pack
hider.place(relx=0.7, rely=0.1)
label.pack()
text_entry.place(relx=0.4, rely=0.1)
button = customtkinter.CTkButton(master=window,
width=120,
height=32,
border_width=0,
corner_radius=10,
text="Keresés",
hover_color="lightblue",
command=submit_input)
button.place(relx=0.7, rely=0.1)
#photo = PhotoImage("weather.png")
#window.iconbitmap("weather.ico")
def mapopen():
#marker_1 = map_widget.set_address(varosformap, marker=True)
#marker_1.set_text(f"{jsonformatumformap['main']['temp']} °C")
varosformap = text_entry.get()
lekerdez = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={varosformap}&appid=a3c3ac028697416ece9bd3c3a7c0f500&units=metric')
jsonformatumformap = json.loads(lekerdez.text)
map_widget = tkintermapview.TkinterMapView(window, width=600, height=400, corner_radius=0)
map_widget.place(relx=0.5, rely=0.3)
map_widget.set_address("budapest")
marker_1 = map_widget.set_address(varosformap, marker=True)
marker_1.set_text(f"{jsonformatumformap['main']['temp']} °C")
#map_widget.zoom()
"""def slider_event(value):
print(value)
slider = customtkinter.CTkSlider(master=window,
width=160,
height=16,
border_width=5.5,
command=slider_event)
slider.place(relx=0.5, rely=0.9)
slider.pack()"""
mapbtn = customtkinter.CTkButton(master=window,
width=120,
height=32,
border_width=0,
corner_radius=10,
text="Megjelenítés térképen",
hover_color="lightblue",
command=mapopen)
mapbtn.place(relx=0.7, rely=0.2)
window.mainloop()
except KeyboardInterrupt:
pass