Re: tkinter icons as bytestrings, not files?
On Tue, 24 Feb 2009 05:56:12 +0100, Peter Billam wrote: Greetings, As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: for image, command in ( ('images/filenew.gif', self.fileNew), ('images/fileopen.gif', self.fileOpen), ('images/filesave.gif', self.fileSave), ('images/editadd.gif', self.editAdd), ('images/editedit.gif', self.editEdit), ('images/editdelete.gif', self.editDelete),): image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) self.toolbar_images.append(image) button = tkinter.Button(toolbar, image=image, command=command) button.grid(row=0, column=len(self.toolbar_images) -1) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's "data=something, format=something")) ... Just dump the contents of the file as a bytestring and use: image = PhotoImage(data=the_byte_string) With no extension, I guess it'll only work with GIF files, as it is the only natively supported image format in tcl/tk (AFAIK...). HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter icons as bytestrings, not files?
En Tue, 24 Feb 2009 02:56:12 -0200, Peter Billam escribió: As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's "data=something, format=something")) ... Almost; see the best documentation source for tkinter: http://effbot.org/tkinterbook/photoimage.htm -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
tkinter icons as bytestrings, not files?
Greetings, As a newbie, starting with Python3, I'm working my way through Mark Summerfield's tkinter examples. In the toolbar, there's lines like: for image, command in ( ('images/filenew.gif', self.fileNew), ('images/fileopen.gif', self.fileOpen), ('images/filesave.gif', self.fileSave), ('images/editadd.gif', self.editAdd), ('images/editedit.gif', self.editEdit), ('images/editdelete.gif', self.editDelete),): image = os.path.join(os.path.dirname(__file__), image) image = tkinter.PhotoImage(file=image) self.toolbar_images.append(image) button = tkinter.Button(toolbar, image=image, command=command) button.grid(row=0, column=len(self.toolbar_images) -1) which are always failing because the icons are in the wrong place and I can't help but wonder if I can put all these little images in the application itself, either as b'whatever' or uuencoded or in svg etc, and then invoke some suitable variation of the image = tkinter.PhotoImage(file=image) or of the button = tkinter.Button(toolbar, image=image, command=command) command ? (I did try help('tkinter.PhotoImage') but didn't spot a magic key (unless it's "data=something, format=something")) ... Regards, Peter -- Peter Billam www.pjb.com.auwww.pjb.com.au/comp/contact.html -- http://mail.python.org/mailman/listinfo/python-list