[Tkinter-discuss] displaying an image

Lynn Oliver raycores at gmail.com
Thu Oct 4 20:23:54 CEST 2012


I know this isn't exactly what you asked, but I am displaying an image in a label in a --onefile distribution, and this code works both while debugging and while running the packaged application:
      
               if getattr(sys, 'frozen', None):
             basedir = sys._MEIPASS
        else:
             basedir = os.path.dirname(__file__)  
        self.photo = tk.PhotoImage(file=os.path.join(basedir, 'myImage.gif'))
        self.myLabel = ttk.Label(self.myFrame, image=self.photo)
        self.myLabel.grid()

Lynn

On Oct 4, 2012, at 10:29 AM, Michael O'Donnell <michael.odonnell at uam.es> wrote:

> Hi Matthew,
> 
> Your first line should in fact be:
> 
> from PIL import Image
> 
> ...then your line:
> 
> my_image = Image.open("imagepath.jpg")
> 
> Mick
> 
> On Thu, Oct 4, 2012 at 7:16 PM, Matthew Ngaha <chigga101 at gmail.com> wrote:
>> 
>> im trying to display an image. Ive tried different code from several
>> tutorials but they seem outdated and nothing works. here's 1 line that
>> makes me give up.
>> 
>> 
>> 
>> this line returns an error of Image doesnt have attribute open, yet
>> this is what my tutorial has shown me. can anyone please help?
>> 
>> any new tkinter tutorials around?
>> _______________________________________________
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
>> http://mail.python.org/mailman/listinfo/tkinter-discuss
> 
> 
> 
> -- 
> 
> Not sent from my iPhone
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20121004/4804f629/attachment.html>


More information about the Tkinter-discuss mailing list