http://www.perlmonks.org?node_id=825281


in reply to Re: Perl Tk: How Can I get the MainWindow Configuration?
in thread Perl Tk: How Can I get the MainWindow Configuration?

I want to show the width and height of the MainWindow in status bar and change the Title of the Window Based on the arguments.
Is there any function or any way to achieve this?

  • Comment on Re^2: Perl Tk: How Can I get the MainWindow Configuration?

Replies are listed 'Best First'.
Re^3: Perl Tk: How Can I get the MainWindow Configuration?
by stefbv (Curate) on Feb 25, 2010 at 12:37 UTC
    Like this?:
    ... my $height = $mw->screenheight; my $width = $mw->screenwidth; my $geom = $mw->geometry; $mw->title("New Title ($geom)");
    Update:

    Changed code to show geometry of the window instead of the screen.

    Update2: Width and height (for any widget):
    my $height = $mw->height; my $width = $mw->width; $mw->title("New Title ($width x $height)");

    Other options are here: Tk::Widget

      Yes I got It..
      Thanks
Re^3: Perl Tk: How Can I get the MainWindow Configuration?
by Marshall (Canon) on Feb 25, 2010 at 15:33 UTC
    I am confused about this. When you create a MainWindow, you can specify the minimum size for the x,y coordinates. So you know that. You should also know the title text that you want.

    change the Title of the Window Based on the arguments. Change based upon what arguments?

      Usually you don't specify the geometry of the window when you create it, but let Tk calculate and display a minimum window, just to fit all the widgets inside. In this case the 'width', 'height' and 'geometry' methods ca be used to find out the result.

      That is because Tk widgets may get different sizes with different screen resolutions and/or fonts.

      The title can be changed, let's say, according to some action you choose by menu.

      Regards, Stefan

      I didn't specify the minimum size for the main window, you can resize the window. After resizing I want the current size of the Main Window.

      I will give the file name as argument. So the Main Window title should be the name of the file.
      Then I want the current title of the Main window.

        I am having a hard time understanding what you are trying to do. It would be helpful if you could post some simple code to demonstrate what you have and how it fails to do what you want.

        I don't know a way of forcing a MainWindow to display less than the available widgets. Is that what you are trying to do? And if so, then why?

        The "title bar" for the main window is normally a constant "set it once" deal and is usually the name of your application. In any event you know what that title is because you set it!

        The normal way to do what it sounds like you want is to make a new top level window with a new title for that window and probably a label for the file name that you have just opened.

        The user and/or Tk re-sizes windows, not your program!

        The Tk minimum main window size as you have already seen is in points, not lines of text or widgets, etc. There is not an easy way to figure out how that number of points relates to what is displayed upon the screen.

        You can ask questions like is line #45 of this text widget visible on the screen or not? There are methods to pack and re-pack widgets and re-display the screen.