Hi Perl Monks, I am trying to write a simple program in Perl/Tk,
This program creates a Main window which contains a Button named New Window
This button opens other Toplevel window Child Window which contains a text box and button
Enter the text in the text box and click on CREATE btn which opens a top level window with the text as tile.
On clicking on CREATE btn should open multiple Toplevel windows with different titles.
If the titles are same the existing window should raise.
This toplevel window contains Refresh and Close Buttons.
Here i am facing the problem. When i click on the Close button the top level window closes.
But when i click on Refresh Btn, other toplevel window will be refreshed instead of the one that is intended.
Please help me in resolving this issue. Here is the code that i am working with:
#!/usr/local/bin/perl use strict; use Tk; my $obj; my $fp; my $info; my $entframe; #Creating the Main Widow my $wind = new MainWindow; $wind->title("Main Window"); my $frame = $wind->Frame()->pack; $frame->Button(-text => 'New Window', -command =>\&newwin) ->pack(-side =>'left', -ipady => 5, -p +ady=>15); MainLoop; sub newwin { if(! Exists($obj->{mw})) { $obj = bless {mw => $wind->Toplevel()}; $obj->{mw}->title("Child Window"); $obj->{mw}->minsize(qw(200 200)); #The entered text will be the title of the next toplevel windo +w my $frm = $obj->{mw}->Frame()->pack(-side => 'top' ); $frm->Label(-text=>"Enter the Toplevel Name")->pack(); $frm->Entry(-textvariable =>\$fp)->pack(); $obj->{frame1} = $obj->{mw}->Frame()->pack(); $obj->{frame1}->Button(-text => 'CREATE', -command =>[\&Create +_Window, $obj])->pack(-side =>'left', -ipady => 5, -pady=>15); } else { $obj->{mw}->deiconify (); $obj->{mw}->raise (); } } #Creating the Toplevel window sub Create_Window { my $self = $_[0]; my $Obj_Id = $fp ; if (Exists ($self->{windows}{$Obj_Id}{win})) { $self->{windows}{$Obj_Id}{win}->deiconify (); $self->{windows}{$Obj_Id}{win}->raise (); return; } $info = $self->{windows}{$Obj_Id} = {}; $info->{win} = $wind->Toplevel(); my $path = $wind->toplevel; $info->{win}->title($fp); $info->{win}->minsize(qw(200 200)); $info->{win}->focus(); $info->{$entframe} = $info->{win}->Frame()->pack(-side => 'top' ); $info->{$entframe}->Entry()->pack(); $info->{$entframe}->Entry()->pack(); $info->{frame} = $info->{win}->Frame()->pack(-side => 'bottom' ); $info->{frame}->Button(-text => 'Refresh', -command =>[\&refresh, +$self, $Obj_Id])->pack(-side=>'left'); $info->{frame}->Button ( -text => 'Close', -command => [\&closeChi +ld, $self, $Obj_Id] )->pack(-side=>'left'); } #Close the particular Child Window sub closeChild { my ($self, $winId) = @_; my $title = $self->{windows}{$winId}{win}->cget(-title); $self->{windows}{$winId}{win}->destroy (); delete $self->{windows}{$winId}; } #Refresh the particular Child Window sub refresh { my ($self, $winId, $f) = @_; if (Exists($info->{$entframe})) { $info->{$entframe}-> destroy() ; } ############################################################# #Here i am unable to get the reference of the toplevel window $info->{$entframe} = $self->{windows}{$winId}{win}->Frame()->pa +ck(-side => 'top' ); $info->{$entframe}->Entry()->pack(); }

In reply to Toplevel Window References in Perl Tk by lara26

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.