main.py aktualisiert
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
import requests
|
||||
import customtkinter as ctk
|
||||
import threading
|
||||
import json
|
||||
import os
|
||||
import webbrowser
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
try:
|
||||
import customtkinter as ctk
|
||||
except ImportError:
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "customtkinter"])
|
||||
import customtkinter as ctk
|
||||
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "requests"])
|
||||
import requests
|
||||
|
||||
app = ctk.CTk()
|
||||
|
||||
@@ -196,7 +206,7 @@ def openAPIPopup():
|
||||
APIlabel = ctk.CTkLabel(popup, text="Enter your API key:")
|
||||
APIlabel.pack(pady=(15, 5))
|
||||
|
||||
APIKeyGet = ctk.CTkLabel(popup, text="How to get free API key", text_color="#3366d6", cursor="hand2")
|
||||
APIKeyGet = ctk.CTkLabel(popup, text="How to get free API key", text_color="#3366d6", cursor="hand2", font=("Arial", 12, "underline"))
|
||||
APIKeyGet.bind("<Button-1>", openWeatherLink)
|
||||
APIKeyGet.pack(pady=5)
|
||||
|
||||
@@ -262,80 +272,6 @@ def openAPIPopup():
|
||||
safeAPI = ctk.CTkButton(popup, text="Safe API key", command=getAPIkey)
|
||||
safeAPI.pack(pady=10)
|
||||
|
||||
|
||||
|
||||
|
||||
if not APIKey:
|
||||
app.after(500, openAPIPopup)
|
||||
|
||||
|
||||
|
||||
searchPage.pack(fill="both", expand=True)
|
||||
searchPage.pack(pady=200)
|
||||
|
||||
searchFrame = ctk.CTkFrame(searchPage, width=500)
|
||||
searchFrame.pack(pady=30, anchor="center")
|
||||
|
||||
searchLabel = ctk.CTkLabel(searchFrame, text="Which city do you want to know the weather?", font=("Arial", 30))
|
||||
searchLabel.pack(pady=5, padx=15)
|
||||
|
||||
cityEntry = ctk.CTkEntry(searchPage, placeholder_text="Enter City", font=("Arial", 22, "bold"), width=800, height=70)
|
||||
cityEntry.pack(pady=10, anchor="center")
|
||||
|
||||
cityEntry.bind("<Return>", lambda event: doSearch())
|
||||
|
||||
resultTitle = ctk.CTkLabel(resultPage, text="Weather: ", font=("Arial", 60, "bold"))
|
||||
resultTitle.pack(pady=20)
|
||||
|
||||
###################################################
|
||||
#### WEATHER FRAMES ####
|
||||
###################################################
|
||||
|
||||
cardsFrame = ctk.CTkFrame(resultPage, fg_color="transparent")
|
||||
cardsFrame.pack(fill="both", expand=True, padx=20, pady=20)
|
||||
|
||||
weatherTempFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherTempFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherTempFrame.pack_propagate(False)
|
||||
|
||||
weatherTempTitle = ctk.CTkLabel(weatherTempFrame, text="Temperature", font=("Arial", 45, "bold"))
|
||||
weatherTempTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherTempLabel = ctk.CTkLabel(weatherTempFrame, font=("Arial", 25))
|
||||
weatherTempLabel.pack(expand=True, anchor="n")
|
||||
|
||||
weatherGeneralFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherGeneralFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherGeneralFrame.pack_propagate(False)
|
||||
|
||||
weatherGeneralTitle = ctk.CTkLabel(weatherGeneralFrame, text="General:", font=("Arial", 45, "bold"))
|
||||
weatherGeneralTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherGeneralLabel = ctk.CTkLabel(weatherGeneralFrame, font=("Arial", 25))
|
||||
weatherGeneralLabel.pack(expand=True, anchor = "n")
|
||||
|
||||
weatherWindFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherWindFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherWindFrame.pack_propagate(False)
|
||||
|
||||
weatherWindTitle = ctk.CTkLabel(weatherWindFrame, text="Wind", font=("Arial", 45, "bold"))
|
||||
weatherWindTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherWindLabel = ctk.CTkLabel(weatherWindFrame, font=("Arial", 25))
|
||||
weatherWindLabel.pack(expand=True, anchor = "n")
|
||||
|
||||
|
||||
##################################################
|
||||
#### Return Button ####
|
||||
##################################################
|
||||
|
||||
returnButton = ctk.CTkButton(resultPage, text="Return", command=returnButtonClick)
|
||||
returnButton.pack(pady=10)
|
||||
|
||||
|
||||
ErrorFrame = ctk.CTkFrame(searchPage)
|
||||
ErrorLabel = ctk.CTkLabel(ErrorFrame, text="")
|
||||
|
||||
def doSearch():
|
||||
threading.Thread(target=searchWeather, daemon=True).start()
|
||||
|
||||
@@ -433,6 +369,78 @@ def showSearch():
|
||||
resultPage.pack(fill="both", expand=True)
|
||||
|
||||
|
||||
if not APIKey:
|
||||
app.after(500, openAPIPopup)
|
||||
|
||||
|
||||
|
||||
searchPage.pack(fill="both", expand=True)
|
||||
searchPage.pack(pady=200)
|
||||
|
||||
searchFrame = ctk.CTkFrame(searchPage, width=500)
|
||||
searchFrame.pack(pady=30, anchor="center")
|
||||
|
||||
searchLabel = ctk.CTkLabel(searchFrame, text="Which city do you want to know the weather?", font=("Arial", 30))
|
||||
searchLabel.pack(pady=5, padx=15)
|
||||
|
||||
cityEntry = ctk.CTkEntry(searchPage, placeholder_text="Enter City", font=("Arial", 22, "bold"), width=800, height=70)
|
||||
cityEntry.pack(pady=10, anchor="center")
|
||||
|
||||
cityEntry.bind("<Return>", lambda event: doSearch())
|
||||
|
||||
resultTitle = ctk.CTkLabel(resultPage, text="Weather: ", font=("Arial", 60, "bold"))
|
||||
resultTitle.pack(pady=20)
|
||||
|
||||
###################################################
|
||||
#### WEATHER FRAMES ####
|
||||
###################################################
|
||||
|
||||
cardsFrame = ctk.CTkFrame(resultPage, fg_color="transparent")
|
||||
cardsFrame.pack(fill="both", expand=True, padx=20, pady=20)
|
||||
|
||||
weatherTempFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherTempFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherTempFrame.pack_propagate(False)
|
||||
|
||||
weatherTempTitle = ctk.CTkLabel(weatherTempFrame, text="Temperature", font=("Arial", 45, "bold"))
|
||||
weatherTempTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherTempLabel = ctk.CTkLabel(weatherTempFrame, font=("Arial", 25))
|
||||
weatherTempLabel.pack(expand=True, anchor="n")
|
||||
|
||||
weatherGeneralFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherGeneralFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherGeneralFrame.pack_propagate(False)
|
||||
|
||||
weatherGeneralTitle = ctk.CTkLabel(weatherGeneralFrame, text="General:", font=("Arial", 45, "bold"))
|
||||
weatherGeneralTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherGeneralLabel = ctk.CTkLabel(weatherGeneralFrame, font=("Arial", 25))
|
||||
weatherGeneralLabel.pack(expand=True, anchor = "n")
|
||||
|
||||
weatherWindFrame = ctk.CTkFrame(cardsFrame, width=500, height=350)
|
||||
weatherWindFrame.pack(side="left", expand=True, fill="both", padx=10)
|
||||
weatherWindFrame.pack_propagate(False)
|
||||
|
||||
weatherWindTitle = ctk.CTkLabel(weatherWindFrame, text="Wind", font=("Arial", 45, "bold"))
|
||||
weatherWindTitle.pack(expand=True, fill="both", pady=(20,10))
|
||||
|
||||
weatherWindLabel = ctk.CTkLabel(weatherWindFrame, font=("Arial", 25))
|
||||
weatherWindLabel.pack(expand=True, anchor = "n")
|
||||
|
||||
|
||||
##################################################
|
||||
#### Return Button ####
|
||||
##################################################
|
||||
|
||||
returnButton = ctk.CTkButton(resultPage, text="Return", command=returnButtonClick)
|
||||
returnButton.pack(pady=10)
|
||||
|
||||
|
||||
ErrorFrame = ctk.CTkFrame(searchPage)
|
||||
ErrorLabel = ctk.CTkLabel(ErrorFrame, text="")
|
||||
|
||||
|
||||
cityEntry.bind("<Return>", lambda event: doSearch())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user