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
|
import urllib
import json
from tkinter import *
from tkinter.messagebox import *
import webbrowser
import datetime
ville= str(input("quelle ville ?:"))
webbrowser.open("https://maps.googleapis.com/maps/api/staticmap?center="+ville+"&zoom=14&size=400x400&key=AIzaSyCAAMXESmzBli5m30ZUOqW8UbuqNGIJtp8")
f = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?q='+ville+'&APPID=1f8e93176443bf6677cc11c5935b43cc')
#CleAPIGoogle: AIzaSyCAAMXESmzBli5m30ZUOqW8UbuqNGIJtp8
var = f.read()
L=str(var)
s=L[2:-1]
json_acceptable_string = s.replace("'", "\"")
d = json.loads(json_acceptable_string)
#code avec tkinter
fenetre = Tk()
label = Label(fenetre, text="Quelle Ville?")
label.pack()
def recupereInfo(chaine, dico) :
if chaine == "Température" :
return (str(dico['main']['temp']),"Kelvins")
if chaine == "Pression" :
return (str(dico['main']['pressure']),"hPa")
if chaine == "Humidité" :
return (str(dico['main']['humidity']), "%")
if chaine == "Vitesse du vent" :
return (str(dico['wind']['speed']), "mps")
if chaine == "Nuages" :
return (str(dico['clouds']['all']), "%")
if chaine == "Levé du soleil" :
return str(dico['sys']['sunrise'])
if chaine == "Couché du soleil" :
return str(dico['sys']['sunset'])
if chaine == "Temps général" :
return str(dico['weather']['description'])
def recupere():
showinfo("Choix de la ville", entree.get())
ville= str(input("quelle ville ?:"))
webbrowser.open("https://maps.googleapis.com/maps/api/staticmap?center="+ville+"&zoom=14&size=400x400&key=AIzaSyCAAMXESmzBli5m30ZUOqW8UbuqNGIJtp8")
f = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?q='+ville+'&APPID=1f8e93176443bf6677cc11c5935b43cc')
#CleAPIGoogle: AIzaSyCAAMXESmzBli5m30ZUOqW8UbuqNGIJtp8
var = f.read()
L=str(var)
s=L[2:-1]
print(s)
json_acceptable_string = s.replace("'", "\"")
d = json.loads(json_acceptable_string)
def recupereListe():
showinfo("Informations", recupereInfo(list_items[liste.curselection()[0]], d) )
ville = StringVar()
ville.set("")
entree = Entry(fenetre, textvariable=ville, width=30)
entree.pack()
bouton = Button(fenetre, text="Valider", command=recupere)
bouton.pack()
value = StringVar()
bouton1 = Radiobutton(fenetre, text="Aujourd'hui", variable=value, value=1)
bouton2 = Radiobutton(fenetre, text="Demain", variable=value, value=2)
bouton3 = Radiobutton(fenetre, text="Sur la semaine", variable=value, value=3)
bouton1.pack()
bouton2.pack()
bouton3.pack()
liste = Listbox(fenetre)
list_items= ["Température","Pression","Humidité","Vitesse du vent","Nuages","Levé du soleil","Couché du soleil","Temps général"]
k=1
for element in list_items :
liste.insert(k, element)
k = k+1
liste.pack()
boutonliste = Button(fenetre, text="Valider", command=recupereListe)
boutonliste.pack()
boutonfermer=Button(fenetre, text="Fermer", command=fenetre.quit())
fenetre.mainloop() |
Partager