Now, I would like to capture any user changes/inputs and write a text file consisting of: LABEL=ENTRY\n LABEL=ENTRY\n ..

So open a file, and loop thru your hash and print to the file. You can do this by adding code in the run callback, to open the file, loop thru your hash, print the keys values, then close the file. I will show how this is done in the script below, which shows how to sort your keys properly.

The problem with sorting your keys, is that you have a mixed alpha-numeric string. if you just use sort on the keys, you will end up with the typical alpha order 1,10,2,3, etc. So you must split you keys into alpha and numeric fields, then sort on them. I show this below. Now sorting is a big topic, and I won't explain the details here, but you can see List Processing, Filtering, and Sorting. As you work thru it, save the examples as recipes for various sorts. So here is sort, and print to file.

#!/usr/bin/perl use warnings; use strict; my %tools = ( 'program1' => { 'PARM1' => 1, 'PARM2' => 'n', 'PARM3' => + 'y', 'PARM4' => 'n', 'PARM5' => 'y', 'PARM6' +=> 'n', 'PARM7' => 'y', 'PARM8' => 'n', 'PARM9' +=> 'y', 'PARM10' => 'n' }, 'program2' => { 'PARM1' => 1, 'PARM2' => 2, 'PARM3' => 3 +, 'PARM4' => 4, 'PARM5' => 5, 'PARM6' => 6, 'PARM7' => 7 +, 'PARM8' => 8, 'PARM9' => 9, 'PARM10' => 10 }); open (my $oh,"> $0-settings.txt") or warn "$!\n"; foreach my $tab (sort keys %tools){ print $oh "\n$tab\n"; foreach my $parm (custom_sort(\%{$tools{$tab}})) { print $oh " $parm = $tools{$tab}{$parm}\n"; } } close $oh; #for my $key ( custom_sort(\%hash) ) { # print "Key: $key\n"; #} sub custom_sort { my $hash = shift; return map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map { [ $_, /(\w+)(\d+)$/ ] } keys %$hash; }

As far as detecting changes go, there are a few ways to do it. One way, is to make a callback for the -raisecmd of the notebook options. Google for examples. The idea is when a tab is selected (raised), the -raisecmd callback loops thru all the values on that page and stores them somehow.. You would need to store the previous tab, as well as the current tab. When a new tab is raised, the -raisecmd would loop thru all entries on the previous page, and compare them to the original. It is simple bookkeeping. If a difference is detected, do whatever.

Another option, might be to try to use the validate callback of the entry widgets... it might be a simpler approach. If an attempt is made to an entry, a callback is triggered. That can flag that entry as "changed", whether you actually change the data or not.

So it's really up to you and your program's needs, as to how you detect changes. The absolute simplest approach, is to maintain a separate hash of all the values, and on every -raisecmd, loop thru the backup hash, and compare the entries, and detect differences. It may waste a few cpu cycles, but it is a simple way.


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^7: clunky Tk GUI by zentara
in thread clunky Tk GUI by honyok

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.