Hi Monks,

I am writing a code to convert Celsius to Fahrenheit. The problem is that, I want the user to enter the number of values of celcius he wants to convert (can be implemented by a scale, range from 1 to 10). For example, if user enters 1 and pushes a button. Then the GUI will create an entry box and a text box where the output is printed. If he enters 2 and pushes the button, the GUI will create 2 entry boxes and 2 different text boxes, where the output can be printed. so in this case, if user enters 1 entry celcius value per box, in the other 2 text boxes, the individual results of farienheit will be shown. Can the GUI be dynamically changed in this manner?

I had asked this question earlier, but I think my question was not properly understandable, and though some people tried to help out, they couldn't understand the question properly.

I have also updated my code now, so that it is more clear. What I am trying to do is 2 cases. one in which the user enters 1 in the scale ($numce1), in this case, I want to create 1 entry box and one text box. If the user enters 2, I want to create 2 entry boxes and 2 text boxes which show the output. This code is not correct, I dont know what I am doing wrong. I also want to know how to expand this for 10 cases. i.e. 10 input Celsius boxes and 10 output Fahrenheit boxes

#user chooses 1 in scale. and pushes button #Enters Celcius in one entry box created. Celcius: 1 #views result in text box Farienhiet:33.8 #user chooses 2 in scale and pushes button. 2 entry boxes and 2 text b +oxes are created Enters 1 in one entry box and 0 in another entry box. Views result as 33.8 in one box and 32 in another box.

This is what I am trying to accomplish. Am I in the right direction?

#!/usr/local/bin/perl use Tk; use Tk::Pane; use Tk::Balloon; use strict; use warnings; #my $mw = new MainWindow; # Main Window our $formal_name = 'Celcius to Farienhiet Converter'; my $mw = MainWindow->new( -title => "$formal_name"); $mw->configure( -menu => my $menubar = $mw->Menu ); my $menu_help = $menubar->cascade( -label => '~Help' ); $menu_help->command( -label => "About", -command => sub { GUS::help_about::start_MainLoop() }, ); my $VARIABLE; my $VARIABLE_sec; my $numcel = 1; my $scl = $mw -> Scale(-label=>"No of Celcius Values to Enter:", -orient=>'h', -digit=>1, -from=>1, -to=>2, -variable=>\$numcel, -tickinterval=>1); my $but_sec = $mw -> Button(-text=>"Push Me", -command =>\&push_button +_sec) -> pack(); sub push_button_sec { if ($numcel ==1) { my $frm_name = $mw -> Frame() -> pack(); my $lab = $frm_name -> Label(-text=>"Enter Celsius Value:") -> pack(); my $ent = $frm_name -> Entry(-textvariable=>\$VARIABLE) -> pack(); my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button_old +) -> pack(); #Text Area my $frm_name2 = $mw -> Frame() -> pack(); my $lab2 = $frm_name2 -> Label(-text=>"Farienhiet:") -> pack(); my $txt = $mw -> Text(-width=>40, -height=>10) -> pack(); MainLoop; #This function will be executed when the button is pushed sub push_button_old { my $celsius = $ent -> get(); my $farienhiet = ($celsius*9/5)+32; my $msg = sprintf( "%s Celsius = %3.1f Fahrenheit\n", $celsius, $f +arienhiet ); $txt -> insert('end', $msg); } } if ($numcel ==2) { my $frm_name = $mw -> Frame() -> pack(); my $lab = $frm_name -> Label(-text=>"Enter Celsius Value 1:") -> pack( +); my $ent = $frm_name -> Entry(-textvariable=>\$VARIABLE) -> pack(); my $frm_name_sec = $mw -> Frame() -> pack(); my $lab_sec = $frm_name_sec -> Label(-text=>"Enter Celsius Value 1:") +-> pack(); my $ent_sec = $frm_name_sec -> Entry(-textvariable=>\$VARIABLE_sec) -> + pack(); my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) -> + pack(); #Text Area my $frm_name2 = $mw -> Frame() -> pack(); my $lab2 = $frm_name2 -> Label(-text=>"Farienhiet1:") -> pack(); my $txt = $mw -> Text(-width=>40, -height=>2) -> pack(); my $frm_name2_sec = $mw -> Frame() -> pack(); my $lab2_sec = $frm_name2_sec -> Label(-text=>"Farienhiet2:") -> pack( +); my $txt_sec = $mw -> Text(-width=>40, -height=>2) -> pack(); MainLoop; sub push_button { my $celsius = $ent -> get(); my $farienhiet = ($celsius*9/5)+32; my $msg = sprintf( "%s Celsius = %3.1f Fahrenheit\n", $celsius, $f +arienhiet ); $txt -> insert('end', $msg); my $celsius_sec = $ent_sec -> get(); my $farienhiet_sec = ($celsius_sec*9/5)+32; my $msg_sec = sprintf( "%s Celsius = %3.1f Fahrenheit\n", $celsius +_sec, $farienhiet_sec ); $txt_sec -> insert('end', $msg); } } }

In reply to set multiple entry boxes and text output boxes in perl TK at run time by Ganesh Bharadwaj1

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.