error with py2exe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nazish zehra
    New Member
    • Dec 2011
    • 31

    error with py2exe

    I am using tkinter to make a gui and then converting it to .exe using py2exe.My gui also includes .gif images. Code I am using in setup.py is:
    Code:
    from distutils.core import setup
    import py2exe
    
    setup(console=['gui.py'])
    i run the following command from console:
    Code:
    python setup.py py2exe
    it executes and makes gui.exe but when i run gui.exe from commandline it gives the following error:
    Code:
    C:\>dist\gui
    Traceback (most recent call last):
      File "gui.py", line 226, in <module>
      File "Tkinter.pyc", line 3282, in __init__
      File "Tkinter.pyc", line 3238, in __init__
    _tkinter.TclError: couldn't open "ss.gif": no such file or directory
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Obviously the image file was not found. I don't have an answer for how to use an external image file from an executable. However, I can tell you how to embed the gif image in your source code for compiling. Following is sample code for displaying the image in a Tkinter widget:
    Code:
            self.imageFrame = Tkinter.Frame(self.masterFrame)
            self.imageFrame.pack(side=LEFT, expand=1, fill=BOTH)
            self.image = Tkinter.PhotoImage(master=self.imageFrame, data=imagedata)
            self.imageLabel = Tkinter.Label(self.imageFrame, image=self.image)
            self.imageLabel.pack(side=LEFT, anchor="n", padx=2, pady=2)
    The image data (imagedata in the snippet above) is made by assignment of the ascii text printed to stdout by the following code:
    Code:
    # Create string representing image
    import base64
    print "icon='''\\\n" + base64.encodestring(open("ss.gif", "rb").read()) + "'''"
    The image data assignment looks something like this:
    Code:
    imagedata = '''\
    R0lGODlhzAGDAXcAACH5BAEAAAAALAAAAADMAYMBhwAAAIAAAACAAICAAAAAgIAAgACAgICAgMDA
    wP8AAAD/AP//AAAA//8A/wD//////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAAZgAAmQAAzAAA/wAz
    AAAzMwAzZgAzmQAzzAAz/wBmAABmMwBmZgBmmQBmzABm/wCZAACZMwCZZgCZmQCZzACZ/wDMAADM
    .... snip ....
    LSegm7q95VuMVRe+q9vA1VHGVM9HNdwtqjP9XNxI2tHHldzJHaKAAAA7
    '''

    Comment

    • nazish zehra
      New Member
      • Dec 2011
      • 31

      #3
      image is there in the same folder .when i run gui.py it runs without any error displaying the image but exe file gives error.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Did you try including the full path to the image file in your source code?

        Comment

        • nazish zehra
          New Member
          • Dec 2011
          • 31

          #5
          its solved after giving the full path.thankyou

          Comment

          Working...