class doesn't open its window - newbie question


Chris Hare

I am a newbie to python, but not programming.

I have a menubar item

displaySubMenu.add_command(label="External", command=externalDisplay)

externalDisplay is a new class, which I have already imported. The class is here:

from Tkinter import *
from datetime import datetime, date, time
import urllib
from PIL import Image
#import Image # PIL required
import ImageTk

backColor = "Gray"
highcolor = "Green"
entryColor = "Cyan"
okColor = "Green"
warnColor = "Red"

class externalDisplay(Frame):

def __init__(self,callSign,nexrad):
"""Initialize yourself"""
self.callSign = callSign
self.nexrad = nexrad
#"""Initialise the base class"""

"Set the Window Title"""
#self.title( "Test")

self.findu = "" + self.callSign + "&radar=" + self.nexrad

"""Display the main window" with a little bit of padding"""

def CreateWidgets(self):
#"""Create all the widgets that we need"""
self.f = Frame(self, bd=0, bg=backColor)
self.title = "netcomm Online Radar"
# Insert the date and time the radar image was updated
self.lblLastUpdate = Label(self.f, text="Last Updated: " + str(, bg=backColor)
self.lblLastUpdate.grid( row=0, column=0, sticky=W)
self.btnRefresh = Button(self.f, text="Refresh", command=handlesExternalDisplayByClick, bg=backColor,highlightbackground=okColor,highlightcolor=highcolor)
self.btnRefresh.grid(row=0, column=1)
self.btnRefresh = Button(self.f, text="Close", command=self.destroy, bg=backColor,highlightbackground=warnColor,highlightcolor=highcolor)
self.btnRefresh.grid(row=0, column=2)
# Start the download from findu
# This gets the image and saves it to the local disk as "image.png"
# NOTE - will ideally want to conver this to GIF and save it using
# the date as part of the filename so the net can be re-created
# for reporting and to create a flipbook of the radar images
urllib.urlretrieve(self.findu, "image.png")"image.png").save("image.gif") = PhotoImage(file="image.gif")
# create a canvas of the appropriate size for the image
self.w = Canvas(self.f, width=600, height=550)
# convert it into a photo item we can use in the display
self.netRadarImage = Label(self.w,
self.netRadarImage.image =
self.w.grid(row=1, column=0, columnspan=3)
self.netRadarImage.grid( row=1, column=0)

def handlesExternalDisplayByClick(self):
# destroy the existing frame the radar is in
# rebuild the radarWidgets

def handlesRadarRefreshByClick(self):
# destroy the existing frame the radar is in
# rebuild the radarWidgets

if __name__ == "__main__":
guiFrame = externalDisplay("AE5PL-10","fws")

The problem is that the window defined in the class never appears, and I don't know why. I would like to get all of the code for the window into a single file which I import, but since I can't make this work right, I don't want to invest the time yet. Eve worse, is that when I run the code as a standalone module and click on the close button, I am left with a tk window instead of the app actually closing.

Any suggestions are appreciated.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question