I am working on a project, and one of our spec is to be able to display PGM images with TKinter. Well, for some reason, after switching the image a specific number of times, our application would always end with a Segmentation Fault...
For debugging purposes, I then made a very simple TKinter program that lists all the images in a directory, and lets the user switch the displayed one using a slider. This program has the same issue: after every 26th image, I get a segmentation faut with a "malloc(): memory corruption".
Here is my debug code:
#!/usr/bin/python3
from tkinter import *
import os
class MainFrame():
def __init__(self, main):
self.input_canvas = Canvas(main, width=640, height=480)
self.input_canvas.grid(column=1, row=1)
self.token = False
self.files = os.listdir('.')
self.files.sort()
self.scale = Scale(main, orient='horizontal', from_=0, to=len(self.files), resolution=1,
tickinterval=1/len(self.files), length=600, command=self.load_image)
self.scale.grid(column=1, row=2)
self.load_image("0")
def load_image(self, scale_value):
# The token is only here to make sure load_image is not called multiple times at the same time
if not self.token:
self.token = True
else:
return
input_pic = PhotoImage(file=self.files[int(scale_value)])
self.input_canvas.create_image(0, 0, anchor=NW, image=input_pic)
self.input_canvas.image = input_pic
self.token = False
if __name__ == '__main__':
root = Tk()
MainFrame(root)
root.mainloop()
I guess I encountered a bug with TKinter, but I didn't find any information about that, so maybe I'm doing something wrong that I just can't see :/
Also, I wanted to use PIL with the ImageTk module, but for some reason it couldn't open our test images (they were blank).
Here is an archive with some of our test images (those are 16bits PGM): https://mega.nz/#!CkxwzaZK!2d0vf4ORHh9H9LqWeKpfaZDTPrsmM89lYntrlO44AOE
Any help is welcome!