Hi all,
I want to know is my solution is 'clean'.
I need good gui response if cpu is very busy. in this example cpu is
compute my photo images on to low res.

in next step i need compute md5 sums for each image etc.
Is it good solution write all gui class as Thread or better way is
write only critical cpu code into thread  like md5 checksums, resizing
etc.

in this example i want use slider if cpu is computing, which is work.
thanks for your comments.
#encoding: utf-8
from PIL import ImageTk, Image
from Tkinter import Tk, Canvas, Frame, Scrollbar
import glob, time
from threading import Thread

class Viewer(Canvas, Thread):
    def __init__(self, parent):
        self.frame = Frame(parent)
        Canvas.__init__(self, self.frame)
        Thread.__init__(self)
        Canvas.grid(self, column=0, row=0)
        
        scroll = Scrollbar(self.frame)
        scroll.grid(column=1, row=0, sticky='ns')
        scroll['command'] = self.yview
        self['yscrollcommand'] = scroll.set
        
        self.images = []
        self.start()
        
    def run(self):
        for num, img in enumerate(glob.glob('*.JPG')):
            #print img
            size = 100, 100
            pil = Image.open(img)
            pil = ImageTk.PhotoImage(pil.resize(size, Image.ANTIALIAS))
            self.images.append(pil)
            self.create_image(5, num*100, image=pil, anchor='nw')
            self.update_idletasks()
            #self.update()
            time.sleep(0.1)
            self['scrollregion'] = self.bbox('all')
        
    def grid(self, **kw):
        self.frame.grid(**kw)
        
if __name__ == '__main__':
    root = Tk()
    app = Viewer(root)
    app.grid(column=0, row=0)
    root.mainloop()
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to