If you have code that actually runs, you should paste the relevant part of the running code when you post (or at least be more careful about typing/pasting it in). What you have here has some glaring errors. Update as you see fit (and mention what you've updated), but when I first saw this post, there were the following problems:
- The first curly brace is a close-brace, not an open-brace -- it doesn't compile.
- You have "opendir(SPAM...)" followed by "close(SPAM)", not "closedir(SPAM)" -- maybe that actually works, but it just seems wrong.
- Is "%temp" actually a global hash (like $mw appears to be a globally declared "MainWindow" widget)? If not, it isn't being declared with "my" where it should be. Likewise for $new in "sub view". (Does the script "use strict", or not? If not, try it, please.)
- You aren't checking for success or errors when opening files in the "view()" sub -- likewise for opening the directory.
As for the symptom -- the buttons appear to be labeled as intended, but you aren't seeing the file name or its contents in the new Toplevel window when you hit a button -- well, it's hard to comment on this, because you say your code runs, but what you've posted won't run, so you haven't posted the code that produces that symptom.
Anyway, you might try initializing the "-command" parameter on the button like this:
...
-command => [ \&view, $open ],
...
This way, the "-command" option gets a reference to an anonymous array; the first element of the array is a reference to a subroutine to be run when the button is clicked, and subsequent elements in the array (one in this case) are parameters to be passed to the subroutine in @_.