[Tkinter-discuss] TkPhotoImage data-option

shoz fukuda_shozo at yahoo.co.jp
Fri Apr 13 17:23:20 CEST 2012


Hello, Developers

I modified Tkinter on Python 2.7 and use it every time.
Because original Tkinter dosen't execute the following code well:

f = open("apple.ppm", "rb")
pho = Tk.PhotoImage(data=f.read())

I found out what is wrong in Tkinter implement and fixed it.
That is:

*** org/_tkinter.c
--- new/_tkinter.c
***************
*** 947,954 ****
Tcl_Obj *result;

if (PyString_Check(value))
! return Tcl_NewStringObj(PyString_AS_STRING(value),
PyString_GET_SIZE(value));
else if (PyBool_Check(value))
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
else if (PyInt_Check(value))
--- 947,954 ----
Tcl_Obj *result;

if (PyString_Check(value))
! return Tcl_NewByteArrayObj(PyString_AS_STRING(value),
PyString_GET_SIZE(value));
else if (PyBool_Check(value))
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
else if (PyInt_Check(value))

The reason seems that Tcl_NewStringObj() expects UTF-8 string as input
but PyString_AS_STRING() returns ascii string.

Dose anyone verify whether my fixed code is correct or not.

Best regards.
Shozo



More information about the Tkinter-discuss mailing list