python - Tkinter: Display image after opening from dialog -


this first program i'm writing utilizing tkinter, apologize in advance if questions bit naive.

i have 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 have self.open_file command, function:

def open_file(self):     """ function opens file dialog , allows user select single file, displaying on page """     global filename     filename = []     filename.append(str(unicodedata.normalize("nfkd",tkfiledialog.askopenfilename(filetypes=[("astronomical data","*.fit;*fits")])).encode("ascii","ignore")))      in filename:         stretch_type = "linear"         image_manipulation_pyfits.create_png(i,stretch_type)         x = image.open("file.png")         label(image = x).pack() 

i'm there's shorter, more efficient way of writing function, isn't primary goal @ point -- it's work. goal take image x , display in tkinter window. gives me 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) + + self._options(cnf)) tclerror: image specification must contain odd number of elements 

for clarity, prior function takes input .fits image (selected dialog box pops up) , applies linear stretch, saves .png image same directory under name "file.png".

i've googled past day or , haven't been able find threads on error.

one solution have found:

        x = image.open("file.gif")         x = imagetk.photoimage(x)         label = label(image = x)         label.image = x         label.pack() 
  • save image .gif , open
  • need use photoimage imagetk.

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -