TypeError: 'Weather' object is not callable
Question: I'm very new to programming so please excuse me if I lack the correct
terminology.

I'm trying to retrieve an image from a website and post it onto a GUI with
tkinter. It works, insofar as it posts the image on the GUI; however it still
produces an error as per the title of this post.

The section of code that's causing the error is as follows:

    
    
        raw_data = BeautifulSoup(urllib.request.urlopen("http://www.weather.com.au/act/canberra").read())
        image = raw_data("img", ("class", "si"))[0]
        image = image["src"]
        if image == ("/images/icons/5.gif"):
            URL = urllib.request.urlopen("http://www.weather.com.au/images/icons/5.gif").read()
            b64_data = base64.encodestring(URL)
            image = PhotoImage(data = b64_data)
            label = Label(self, image = image).grid(row = 1, column = 2)
            self(image)
    

Narrowed down further it seems line 39 is causing the error.

    
    
    self(image)
    

Full program as follows:

    
    
    #!/usr/bin/env python
    from tkinter import *
    import sys
    import urllib.request
    from urllib.request import urlopen
    import base64
    from bs4 import BeautifulSoup
    
    class Weather(Frame):
    
        def __init__(self, master):
            Frame.__init__(self, master)
            self.configure(bg = "#ededed")
            self.grid()
            self.heading = Label(self, bg = "#ededed", text = "       Temperature      ").grid(row = 0, column = 1, pady = 5)
            self.heading = Label(self, bg = "#ededed", text = "        Picture        ").grid(row = 0, column = 2, pady = 5)
    
            button = Button(self, bg = "#ededed", text = "Canberra", command = self.canberra_data).grid(row = 3, column = 0, sticky = EW)
    
            self.obsVar1 = StringVar()
            label = Label(self, textvariable = self.obsVar1, bg = "#e5e5e5", fg = "#751974").grid(row = 1, column = 1)
            self.obsVar1.set("")
    
        def canberra_data(self):
            soup = BeautifulSoup(urllib.request.urlopen("http://www.bom.gov.au/act/observations/canberra.shtml").read())
            table = soup.find("table", {"id" : "tCANBERRA"}).tbody("tr", "rowleftcolumn")
            for row in soup("th", {"id" : "obs-station-canberra"}):
                for temp in soup("td", {"headers" : "obs-temp obs-station-canberra"}):                                                                       
                   self.obsVar1.set(temp.text)
    
            raw_data = BeautifulSoup(urllib.request.urlopen("http://www.weather.com.au/act/canberra").read())
            image = raw_data("img", ("class", "si"))[0]
            image = image["src"]
            if image == ("/images/icons/5.gif"):
                URL = urllib.request.urlopen("http://www.weather.com.au/images/icons/5.gif").read()
                b64_data = base64.encodestring(URL)
                image = PhotoImage(data = b64_data)
                label = Label(self, image = image).grid(row = 1, column = 2)
                self(image)
    
    master = Tk()
    master.title("Weather Program")
    app = Weather(master)
    master.mainloop()
    

I should add that if the website has updated its image and it's no longer
'5.gif' (being a weather icon it's highly likely) then a picture won't show
up.

Any help or direction would be much appreciated. I've looked high and low but
to no avail. Thank you in advance.


Answer: The line containing self(image) is not correct. The 'self' is not a class,
it's an object. So, if you want to create an object of type Weather and pass
something to its constructor, just call Weather(image).

