Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi everyone!
I have a sizeable perl script that I'd like to add a GUI to. Perl/Tk seems like a good choice (but let me know if you think otherwise). The program itself is about 3000 lines of code; it does various operations on text files, reports on the results in the console and stops to ask for user input five or six times along the way. It's pretty linear, i.e. it executes the first 100 lines, asks the user if they want it to do X and then goes if ($do_x eq "y") {#does X} and keeps working its way down. Essentially, I need be able to set a couple of variables with Tk button presses and such instead of setting them through <STDIN>, hide the console window and print some text in the GUI window instead of the console. The script is cross-platform. On Windows, I need to pack it into an exe with pp, but my testing so far shows that pp works fine with Tk so there shouldn't be any problems there. I'd like to make the GUI optional because some linux/mac users might not be able/willing to install Tk. Now, I've played a bit with Tk, and I know how to make buttons, radiobuttons, listboxes etc. and set variables based on them. I reckon I can build every element I need, but I don't know how to put things together. The GUI elements only show up once the script has reached the MainLoop; statement, so I can't just put MainLoop; at line 3000 where the program ends and sprinkle the GUI elements all over the place where the <STDIN> points currently are. Do I need to put all the "functional" parts of the script in subroutines in order to be able to trigger them with Tk GUI button presses and such? Then I'd end up with a couple of hundred lines of Tk code at the start of the script, ending with MainLoop; and then 3000 lines of the actual perl code below it in various subs. I'd much prefer to keep the current linear structure, but it doesn't seem to be possible...? Also, the explanations and sample code I've found online seem to only deal with static applications where all the GUI elements show up at once when the program is started. I'm not sure how to make a Tk GUI that guides the user through several steps and redraws the window on user input (remove the buttons/text and show the buttons for the next step etc.) In reply to Perl/Tk code structure by elef
|
|