in reply to Tk: pair matching game

Just some comments to help improve your code. :-)

1. If you would put

use Tk::JPEG; use Tk::Png;
in your code, you could extend your filetypes easily, to include gif, jpg, and png.

2. It is a burden on the user to make 70 '40x40' files. It would be easy for you to allow any images in the images dir, and have your program make thumbnails automatically.

3. I didn't have the Splash modules installed, nor did I have 70 images handy, so I couldn't run this, but from looking at your code, I suspect there may be a memory gain when you run this. Have you watched the memory while running?

The reason I suspect this, is that you create a new Photo object in your button's click callback. These Photo objects will hang around in memory. If I was to do this, I would make photo-objects for each thumbnail just once at the start of the script, base64encode them, and stuff them into a hash. Then on your button clicks, just pull the right photo-object out of the hash. To see an example of this , see Tk ImageMap-color-zones

P.S. I've noticed that the most recent version of Imager causes a problem with that node's code. I'll figure it out an post a fix when I find the problem.


I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Tk: pair matching game
by sanPerl (Friar) on Jan 08, 2007 at 07:51 UTC
    Thanks for your suggestions. Yes I should watch for memory usage also.