Re: Problem With Embedded Icon and Python 3.4
On Mon, 28 Mar 2016 10:36:44 +0100, Mark Lawrence wrote: > On 26/03/2016 02:37, Wildman via Python-list wrote: >> On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote: >> >>> On 25/03/2016 05:10, Wildman via Python-list wrote: I have a program that I have been trying to rewrite so it will run on Python 2.7 and 3.4. >>> >>> This http://pythonhosted.org/six/ might come in handy in future. >>> >>> As I'm also climbing the tkinter cliff at the moment I've found anything >>> on stackoverflow from Bryan Oakley to be very helpful. In particular, >>> his answer here >>> http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application >>> really helped me get a grip on things. >>> >>> A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also >>> useful. >>> >>> HTH. >> >> Thanks for the links. Good stuff. Bookmarked. >> > > One I forgot http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html I had already found that one and have it bookmarked. Thanks tho. -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On 26/03/2016 02:37, Wildman via Python-list wrote: On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote: On 25/03/2016 05:10, Wildman via Python-list wrote: I have a program that I have been trying to rewrite so it will run on Python 2.7 and 3.4. This http://pythonhosted.org/six/ might come in handy in future. As I'm also climbing the tkinter cliff at the moment I've found anything on stackoverflow from Bryan Oakley to be very helpful. In particular, his answer here http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application really helped me get a grip on things. A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also useful. HTH. Thanks for the links. Good stuff. Bookmarked. One I forgot http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On Sat, 26 Mar 2016 01:42:37 +, Mark Lawrence wrote: > On 25/03/2016 05:10, Wildman via Python-list wrote: >> I have a program that I have been trying to rewrite so it will >> run on Python 2.7 and 3.4. > > This http://pythonhosted.org/six/ might come in handy in future. > > As I'm also climbing the tkinter cliff at the moment I've found anything > on stackoverflow from Bryan Oakley to be very helpful. In particular, > his answer here > http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application > > really helped me get a grip on things. > > A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also > useful. > > HTH. Thanks for the links. Good stuff. Bookmarked. -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On 25/03/2016 05:10, Wildman via Python-list wrote: I have a program that I have been trying to rewrite so it will run on Python 2.7 and 3.4. This http://pythonhosted.org/six/ might come in handy in future. As I'm also climbing the tkinter cliff at the moment I've found anything on stackoverflow from Bryan Oakley to be very helpful. In particular, his answer here http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application really helped me get a grip on things. A lot of the examples here http://pyinmyeye.blogspot.co.uk/ were also useful. HTH. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On Fri, 25 Mar 2016 00:34:13 -0500, Zachary Ware wrote: > On Fri, Mar 25, 2016 at 12:10 AM, Wildman via Python-list >wrote: >> I have a program that I have been trying to rewrite so it will >> run on Python 2.7 and 3.4. It has been a pain to say the least. >> Thank $DIETY for aliases. Anyway, I got it all working except >> for one thing. The program has an embedded icon. It is displayed >> in the window's titlebar. The icon is a 16x16 png that has been >> base64 encoded using a Linux utility called memencoder. The code >> below works perfectly with Python 2.7. The icon data is complete >> for anyone that wants to try to run this code: >> >> encoded_icon = """\ > [...] >> I tried converting the icon string to a byte variable like this: >> >> encoded_icon = bytes("""\ >> iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj >> (...) >> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") >> >> >> That give me a different error: >> >> Traceback (most recent call last): >> File "./myprogram.py", line 269, in >> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") >> TypeError: string argument without an encoding >> >> I'm not sure what that means. I looks like it wants the string >> to be encoded but it already is. > > The bytes constructor in Python 3 requires you to provide an encoding > (utf-8, ascii, latin-1, koi8, etc) when passing in a string, otherwise > it doesn't know what bytes you want and refuses to guess. You could > fix this by adding `encoding='ascii'` to the bytes() call–but I'm not > certain that that would work in 2.7, and there's a much easier method, > noted later. > >> And why the reference to only >> the last line of the string? > > Because the traceback would be huge if it included the entire function > call, and there's no need to. You can find the error from just that > line. It would be arguably more useful to show the first line, but > that's more difficult to do. > >> I am at a loss here. Any help would be greatly appreciated. > > What you need here is a bytes literal, which is accomplished by > prepending a 'b' to the string literal. Your `encoded_icon = """\` > just needs to become `encoded_icon = b"""\`. See here [1] for more > information. Thanks for the info and the link. That fixed the problem. -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On Fri, 25 Mar 2016 01:30:17 -0400, Terry Reedy wrote: > On 3/25/2016 1:10 AM, Wildman via Python-list wrote: >> I have a program that I have been trying to rewrite so it will >> run on Python 2.7 and 3.4. It has been a pain to say the least. >> Thank $DIETY for aliases. Anyway, I got it all working except >> for one thing. The program has an embedded icon. It is displayed >> in the window's titlebar. The icon is a 16x16 png that has been >> base64 encoded using a Linux utility called memencoder. The code >> below works perfectly with Python 2.7. The icon data is complete >> for anyone that wants to try to run this code: >> >> encoded_icon = """\ > > To make this literal a bytes literal, prepend 'b'. > > encoded_icon = b'''\ Whoopee, that worked! Thank you. -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On Fri, Mar 25, 2016 at 12:10 AM, Wildman via Python-listwrote: > I have a program that I have been trying to rewrite so it will > run on Python 2.7 and 3.4. It has been a pain to say the least. > Thank $DIETY for aliases. Anyway, I got it all working except > for one thing. The program has an embedded icon. It is displayed > in the window's titlebar. The icon is a 16x16 png that has been > base64 encoded using a Linux utility called memencoder. The code > below works perfectly with Python 2.7. The icon data is complete > for anyone that wants to try to run this code: > > encoded_icon = """\ [...] > I tried converting the icon string to a byte variable like this: > > encoded_icon = bytes("""\ > iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj > (...) > ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") > > > That give me a different error: > > Traceback (most recent call last): > File "./myprogram.py", line 269, in > ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") > TypeError: string argument without an encoding > > I'm not sure what that means. I looks like it wants the string > to be encoded but it already is. The bytes constructor in Python 3 requires you to provide an encoding (utf-8, ascii, latin-1, koi8, etc) when passing in a string, otherwise it doesn't know what bytes you want and refuses to guess. You could fix this by adding `encoding='ascii'` to the bytes() call–but I'm not certain that that would work in 2.7, and there's a much easier method, noted later. > And why the reference to only > the last line of the string? Because the traceback would be huge if it included the entire function call, and there's no need to. You can find the error from just that line. It would be arguably more useful to show the first line, but that's more difficult to do. > I am at a loss here. Any help would be greatly appreciated. What you need here is a bytes literal, which is accomplished by prepending a 'b' to the string literal. Your `encoded_icon = """\` just needs to become `encoded_icon = b"""\`. See here [1] for more information. -- Zach [1] https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem With Embedded Icon and Python 3.4
On 3/25/2016 1:10 AM, Wildman via Python-list wrote: I have a program that I have been trying to rewrite so it will run on Python 2.7 and 3.4. It has been a pain to say the least. Thank $DIETY for aliases. Anyway, I got it all working except for one thing. The program has an embedded icon. It is displayed in the window's titlebar. The icon is a 16x16 png that has been base64 encoded using a Linux utility called memencoder. The code below works perfectly with Python 2.7. The icon data is complete for anyone that wants to try to run this code: encoded_icon = """\ To make this literal a bytes literal, prepend 'b'. encoded_icon = b'''\ iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACAVBMVEUmAAAJ AAD/AAAOAAACAAABAAAVAAArAAANAAAPAACMAADqV1dYAAAVAAArAACmKiw2AABcAACM CguXBgcYAACrAgKdGRuZKCuPCAk9AACDAAAFAAABAADQAAAhAAARAAACAAABAAD/AADO AABaAAAfAABFAAD/AAANAAADAAAOAAAHAAD/AAAYAAAL AAADAAAIAAAtAAABAABXAACnAAC7AABoAABsAACdAABy AAATAAAIAAB8AACeCwvDW1vboaHZmJi+Tk6mJSXFcHDNg4O8VlaeEhGEAACVAgLCZmbSkpTM fX3LiImXERJUAAATAAChGhvLZmmlREdnAAATAACgHyCzQUW7WlybRkpXAACLBgepZWqZZWt+ ExSoFRataW+vq7WqucSdc3t3EhMjAABLAACNAgKMICJ3GRtTAACiAACiEhScHR9vAAAk AAABAAABAAD36+v+ /v785+j539/+8/P27+/gwcPz///1urz+WFnTjI3/cXH5dXfn+f3Z6fDQyM7W/v/bs7vfYGbi c3jfkJbI9v++5vO2w82vusT///+h6spZkXRSTlMA AAEAAQAADEdRFwAdVEQKAAEABFtjUDAENFJ9WAIABDUoGwEIFRIf AgJRyunZVjSw2MZsCzrm3NH5egMAjv/YGwGcxL/eIVHu40crvPn+9IoHBUaPjUAEFk5dTREC AQEBAAABAAEAAAIAmCbO4wFiS0dEqr4GV74JcEhZcwAACxMAAAsTAQCanBgA AAAHdElNRQfgAxUUFToQYVhV5klEQVQY02NQZUAGjEwMagzMDCysbGAuO4O6BoMmgxaH to6unr6BoZExp4kpAxeDmbmFpZW1ja2dvYOjEzdQIY+zi6ubO6+Hp5e3D1inr59/QGBQcEho WHgEH5DPHxk1cdLk6JgpU6fFxsUDBRISp8+YOStp9py58+YnpwAFUtMWLFy0OD1jydJlyzOz gAIC2TkrVubm5RcUFhWXlIIMLSuvqKyqFqypratvEAIJCIs0NomKMYtLSEpJg62VkZWTZ2Bo bnFSUFRSVmFobWuHeqzDiYGhs4uhu6cXKuAEFOjrZ0AFThMAxbo5a0L7F4cldEVYdGRh dGU6Y3JlYXRlADIwMTYtMDMtMjFUMTU6MjA6MzMtMDU6MDBXJmdFJXRFWHRkYXRlOm1v ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""" root = Tk() decoded_icon=base64.decodestring(encoded_icon) image_icon = Image.open(io.BytesIO(decoded_icon)) icon = ImageTk.PhotoImage(image_icon) root.call('wm', 'iconphoto', root._w, icon) app = Window(root) root.mainloop() When I run the program with Python 3.4, I get this error: Traceback (most recent call last): File "/usr/lib/python3.4/base64.py", line 519, in _input_type_check m = memoryview(s) TypeError: memoryview: str object does not have the buffer interface bytes do have the buffer interface, so I expect that using bytes instead of str will work. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Problem With Embedded Icon and Python 3.4
I have a program that I have been trying to rewrite so it will run on Python 2.7 and 3.4. It has been a pain to say the least. Thank $DIETY for aliases. Anyway, I got it all working except for one thing. The program has an embedded icon. It is displayed in the window's titlebar. The icon is a 16x16 png that has been base64 encoded using a Linux utility called memencoder. The code below works perfectly with Python 2.7. The icon data is complete for anyone that wants to try to run this code: encoded_icon = """\ iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACAVBMVEUmAAAJ AAD/AAAOAAACAAABAAAVAAArAAANAAAPAACMAADqV1dYAAAVAAArAACmKiw2AABcAACM CguXBgcYAACrAgKdGRuZKCuPCAk9AACDAAAFAAABAADQ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ErkJggg==""" root = Tk() decoded_icon=base64.decodestring(encoded_icon) image_icon = Image.open(io.BytesIO(decoded_icon)) icon = ImageTk.PhotoImage(image_icon) root.call('wm', 'iconphoto', root._w, icon) app = Window(root) root.mainloop() When I run the program with Python 3.4, I get this error: Traceback (most recent call last): File "/usr/lib/python3.4/base64.py", line 519, in _input_type_check m = memoryview(s) TypeError: memoryview: str object does not have the buffer interface The above exception was the direct cause of the following exception: Traceback (most recent call last): File "./myprogram.py", line 276, in decoded_icon=base64.decodestring(encoded_icon) File "/usr/lib/python3.4/base64.py", line 561, in decodestring return decodebytes(s) File "/usr/lib/python3.4/base64.py", line 553, in decodebytes _input_type_check(s) File "/usr/lib/python3.4/base64.py", line 522, in _input_type_check raise TypeError(msg) from err TypeError: expected bytes-like object, not str I tried converting the icon string to a byte variable like this: encoded_icon = bytes("""\ iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj (...) ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") That give me a different error: Traceback (most recent call last): File "./myprogram.py", line 269, in ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""") TypeError: string argument without an encoding I'm not sure what that means. I looks like it wants the string to be encoded but it already is. And why the reference to only the last line of the string? I am at a loss here. Any help would be greatly appreciated. -- GNU/Linux user #557453 Old enough to know better... too young to resist. -- https://mail.python.org/mailman/listinfo/python-list