Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # By Sergio López
- # GPLv3
- # http://daemonfreedom.blogspot.com/
- from Tkinter import * #For GUI
- import urllib2 #For urlopen
- class Application(Frame):
- """For GUI Aplication"""
- def __init__(self, master=None):
- Frame.__init__(self, master)
- self.grid()
- self.myvar =StringVar()
- self.createWidgets()
- def createWidgets(self):
- self.cpLabel = Label(self, text="Código postal:")
- self.textEntry = Entry(self, textvariable=self.myvar)
- self.okButton = Button ( self, text='Ok', command=self.okAction )
- self.quitButton = Button ( self, text='Salir', command=self.quit )
- self.textZone = Text(self, height=8, width=50)
- self.cpLabel.grid(row=1, column=1)
- self.textEntry.grid(row=1, column=2)
- self.okButton.grid(row=1, column=3)
- self.quitButton.grid(row=1, column=4)
- self.textZone.grid(row=3, column=1)
- def okAction(self):
- self.textZone.delete(1.0, END)
- self.myvar = self.textEntry.get()
- self.imp =self.genWeather(self.myvar)
- #self.textZone.insert(END, self.imp)
- self.impList(self.imp)
- def genWeather(self, cp):
- self.cad="http://www.google.com/ig/api?weather="+cp+",spain&hl=es"
- self.lista = []
- self.f = urllib2.urlopen(self.cad)
- self.down = self.f.read()
- self.f.close()
- for self.element in self.down:
- if self.element == "<":
- self.cadena =""
- if self.element == ">":
- self.cadena=self.cadena+">"
- self.lista.append(self.cadena)
- self.cadena=""
- self.cadena =self.cadena+self.element
- self.final=[self.lista[4], self.lista[5], self.lista[13], self.lista[14], self.lista[15], self.lista[16], self.lista[18]]
- return self.final
- def impList(self, paramtolist):
- for self.element in paramtolist:
- self.textZone.insert(END, self.element)
- self.textZone.insert(END, "\n")
- def main():
- app = Application()
- app.master.title("Weather Tkinter")
- app.mainloop()
- return 0
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement