I am using tkinter's label to display an image, and using ctypes to construct an image. I am not comfortable with ctypes and I think I am doing something wrong, and I am seeing wired issues. I will try to explain as much as I can.
The code works for like 1-2 minutes and then crashes, I had to keep uploading new images to reproduce the issue.
Here is the pseudo python code.
self.photo = ImageTk.PhotoImage(self.image)
self.label = tk.Label(parent, image=self.photo, width=480, height=480,
bg='black')
self.label.grid(row = 0, column = 0, sticky = W)
// C function which is called by ctypes:
//int generate_image(int width, int height, char *image)
// ctypes
img_lib = ctypes.CDLL('image_gen.dll')
img_lib.generate_image.argtypes = (ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint8))
// All the below code is in the draw function, which is called periodically
using Threading.
image_data = np.zeros((480 * 480 * 4), dtype=np.uint8)
ctype_image_data = image_data.astype(ctypes.c_uint8)
pointer_image_data =
ctype_image_data.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
ctype_pointer_image_data = ctypes.cast(pointer_image_data,
ctypes.POINTER(ctypes.c_uint8))
#this line modifies the ctype_image_data.
img_lib.generate_image(width, height, ctype_pointer_image_data)
final_image_data = ctype_image_data.reshape(480,480,4)
final_image = Image.fromarray(final_image_data, 'RGBA')
#set the label with the image
self.photo = ImageTk.PhotoImage(final_image)
self.label.configure(image=self.photo, width=0, height=0)
Errors I am seeing are, all are indenpendent
Process finished with exit code -1073741571 (0xC00000FD) Process finished with exit code xxxxxxxxxx (0xC0000005) Process finished with exit code -1073740771 (0xC000041D)
TclError: bad screen distance "tk::EntryAutoScan .83647664.83715176.83715496" TclError: unknown option "1" TclError: bad option "tk::ButtonUp": must be cget or configure And lot of other wiered TclError, it is different most of the times.
All the errors are in the following line, self.label.configure(image=self.photo, width=0, height=0)
User contributions licensed under CC BY-SA 3.0