ok so I trying to get the weather from google and print it to the screen using a wxpython textctrl... so it works to a point i included print statments in the coding so I could see what was being returend... I assigned the values a variable and call the variables to print ... and they do .... then I try to calll the same variable to print the result in the Textctrl window and I keep getting
Google says: It is cloudy and 21C now in New York.
conditions Cloudy
this is the temp 21
this is humidity Humidity: 59%
time 2010-09-18 17:21:51 +0000
Traceback (most recent call last):
File "C:/Python26/Coding with DB/forummm.py", line 66, in <module>
frame = create(None)
File "C:/Python26/Coding with DB/forummm.py", line 6, in create
return Frame1(parent)
File "C:/Python26/Coding with DB/forummm.py", line 38, in __init__
self._init_ctrls(parent)
File "C:/Python26/Coding with DB/forummm.py", line 27, in _init_ctrls
style=0, value= (weather1a))
NameError: global name 'weather1a' is not defined
first I got the pywapi library from (
http://code.google.com/p/python-weather-api/)
this is the code
(sorry there is no tags but Im very new and dont know how to do that yet) Thanks for any help
import wx
import pywapi
import string
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1TEXTCTRL1, wxID_FRAME1TEXTCTRL2,
wxID_FRAME1TEXTCTRL3,
] = [wx.NewId() for _init_ctrls in range(5)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(118, 161), size=wx.Size(401, 492),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(393, 458))
self.WeatherData()
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(393, 458),
style=wx.TAB_TRAVERSAL)
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='weather1a',
parent=self.panel1, pos=wx.Point(128, 96), size=wx.Size(100, 21),
style=0, value= (weather1a))
self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL2, name='textCtrl2',
parent=self.panel1, pos=wx.Point(128, 136), size=wx.Size(100, 21),
style=0, value='textCtrl2')
self.textCtrl3 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL3, name='textCtrl3',
parent=self.panel1, pos=wx.Point(128, 192), size=wx.Size(100, 21),
style=0, value='textCtrl3')
def __init__(self, parent):
self._init_ctrls(parent)
def WeatherData(self):
google_result = pywapi.get_weather_from_google('10001')
noaa_result = pywapi.get_weather_from_noaa('KJFK')
#weather1a
print "Google says: It is " + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + "C now in New York.\n\n"
self.weather1a = str(google_result['current_conditions']['condition'])
print "conditions", self.weather1a
global weather2a
global weather3a
#global weather4a
#global weather5a
self.weather2a = str(google_result['current_conditions']['temp_c'])
print "this is the temp",self.weather2a
self.weather3a = str(google_result['current_conditions']['humidity'])
print "this is humidity", self.weather3a
#self.weather4a = str(google_result['current_conditions']['temp_f'])
self.weather5a = str(google_result['forecast_information']['current_date_time'])
print "time", self.weather5a
#self.weather6a = str( noaa_result[ 'windchill_string'])
#print "windchill",self.weather6a
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = create(None)
frame.Show()
app.MainLoop()