Beefy Boxes and Bandwidth Generously Provided by pair Networks
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found