This is the first program I'm writing utilizing Tkinter, so I apologize in advance if my questions are a bit naive.
I have the following:
class Example(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
menubar = Menu(self)
master.config(menu=menubar)
self.centerWindow(master)
self.Top_Bar(menubar,master)
self.pack(fill = BOTH, expand = 1)
def Top_Bar(self,menubar,master):
fileMenu = Menu(menubar,tearoff=False)
menubar.add_cascade(label="File",menu=fileMenu)
fileMenu.add_command(label="Open",command = self.open_file)
fileMenu.add_command(label="Exit",command = self.quit)
fileMenu = Menu(menubar,tearoff=False)
menubar.add_cascade(label="Edit",menu=fileMenu)
fileMenu = Menu(menubar,tearoff=False)
menubar.add_cascade(label="Shortcuts",menu=fileMenu)
fileMenu = Menu(menubar,tearoff=False)
menubar.add_command(label="About",command = Message_About)
Notice that I have self.open_file
as a command, which is itself a function:
def open_file(self):
""" A function that opens the file dialog and allows a user to select a single file, displaying it on the page """
global filename
filename = []
filename.append(str(unicodedata.normalize("NFKD",tkFileDialog.askopenfilename(filetypes=[("Astronomical Data","*.fit;*fits")])).encode("ascii","ignore")))
for i in filename:
stretch_type = "linear"
image_manipulation_pyfits.create_png(i,stretch_type)
x = Image.open("file.png")
Label(image = x).pack()
I'm certain there's a shorter, more efficient way of writing this function, but that isn't my primary goal at this point -- it's just to get everything to work. My goal is to take this image x
and display it in the Tkinter window. It gives me the error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "tkinter1.py", line 125, in open_file
Label(image = x).pack()
File "C:\python27\lib\lib-tk\ttk.py", line 766, in __init__
Widget.__init__(self, master, "ttk::label", kw)
File "C:\python27\lib\lib-tk\ttk.py", line 564, in __init__
Tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\python27\lib\lib-tk\Tkinter.py", line 2055, in __init__
(widgetName, self._w) + extra + self._options(cnf))
TclError: image specification must contain an odd number of elements
For clarity, the prior function simply takes an input .fits image (selected from the dialog box that pops up) and applies the linear stretch, then saves it as a .png image to the same directory under the name "file.png".
I've Googled for the past day or so and haven't been able to find any threads on this error.