[Tkinter-discuss] displaying an image

Matthew Ngaha chigga101 at gmail.com
Thu Oct 4 20:59:31 CEST 2012


On Thu, Oct 4, 2012 at 7:23 PM, Lynn Oliver <raycores at gmail.com> wrote:
> 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

i am very new to programming and all that code is confusing me:( sorry:)

> Hi Matthew,
>
> Your first line should in fact be:
>
> from PIL import Image
>
> ...then your line:
>
> my_image = Image.open("imagepath.jpg")
>
> Mick

it gave me an ImportError saying no module named PIL


More information about the Tkinter-discuss mailing list