Tkinter Toplevel geometry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    Tkinter Toplevel geometry

    Hi,

    If a user resizes a Toplevel window, or I set a Toplevel's geometry
    using the geometry() method*, is there any way to have the geometry
    reset to that required for all the widgets?

    I think I found what I'm looking for in tk itself:
    """
    13.3. How can I clear the geometry settings for a toplevel?
    If you want to have Tk resize your toplevel to what the toplevel
    requires (ie: the user might have resized it, or a widget was
    removed), use [wm geometry $toplevel].
    """
    [from http://tcl.sourceforge.net/faqs/tk/]



    * for instance, if I want to turn of Tkinter's automatic adjustment of
    the window to fit all the widgets by doing something like
    self.geometry(s elf.geometry()) , is there any way to undo that?

    Thanks,
    Chris

  • James Stroud

    #2
    Re: Tkinter Toplevel geometry

    Chris wrote:
    Hi,
    >
    If a user resizes a Toplevel window, or I set a Toplevel's geometry
    using the geometry() method*, is there any way to have the geometry
    reset to that required for all the widgets?
    >
    I think I found what I'm looking for in tk itself:
    """
    13.3. How can I clear the geometry settings for a toplevel?
    If you want to have Tk resize your toplevel to what the toplevel
    requires (ie: the user might have resized it, or a widget was
    removed), use [wm geometry $toplevel].
    """
    [from http://tcl.sourceforge.net/faqs/tk/]
    >
    >
    >
    * for instance, if I want to turn of Tkinter's automatic adjustment of
    the window to fit all the widgets by doing something like
    self.geometry(s elf.geometry()) , is there any way to undo that?
    >
    Thanks,
    Chris
    >
    Hi Chris,

    I think you are on to something. The equivalent of

    [wm geometry $toplevel]

    in Tkinter would be

    sometop.geometr y()

    Or, equivalently,

    sometop.wm_geom etry()

    Or, calling the underlying tcl/tk interpreter directly

    sometop.tk.call ('wm', 'geometry', str(sometop))

    Which is redundant, but emphasizes the point: This does not resize the
    widget as expected nor does it cause the window to resize upon adding
    new packing slaves--at least for the X11 based Tkinter for mac via the
    fink debian based package manager.

    Really wish things worked according to the docs a lot of the time or
    that they weren't so poorly written. Perhaps they are implying that you
    must pass parameters, however they do not explain how one might generate
    said parameters to get the required size to which they allude. Terribly
    disappointing.

    James

    Comment

    • James Stroud

      #3
      Re: Tkinter Toplevel geometry

      James Stroud wrote:
      Chris wrote:
      >Hi,
      >>
      >If a user resizes a Toplevel window, or I set a Toplevel's geometry
      >using the geometry() method*, is there any way to have the geometry
      >reset to that required for all the widgets?
      >>
      >I think I found what I'm looking for in tk itself:
      >"""
      >13.3. How can I clear the geometry settings for a toplevel?
      >If you want to have Tk resize your toplevel to what the toplevel
      >requires (ie: the user might have resized it, or a widget was
      >removed), use [wm geometry $toplevel].
      >"""
      >[from http://tcl.sourceforge.net/faqs/tk/]
      >>
      >>
      >>
      >* for instance, if I want to turn of Tkinter's automatic adjustment of
      >the window to fit all the widgets by doing something like
      >self.geometry( self.geometry() ), is there any way to undo that?
      >>
      >Thanks,
      >Chris
      >>
      >
      Hi Chris,
      >
      I think you are on to something. The equivalent of
      >
      [wm geometry $toplevel]
      >
      in Tkinter would be
      >
      sometop.geometr y()
      >
      Or, equivalently,
      >
      sometop.wm_geom etry()
      >
      Or, calling the underlying tcl/tk interpreter directly
      >
      sometop.tk.call ('wm', 'geometry', str(sometop))
      >
      Which is redundant, but emphasizes the point: This does not resize the
      widget as expected nor does it cause the window to resize upon adding
      new packing slaves--at least for the X11 based Tkinter for mac via the
      fink debian based package manager.
      >
      Really wish things worked according to the docs a lot of the time or
      that they weren't so poorly written. Perhaps they are implying that you
      must pass parameters, however they do not explain how one might generate
      said parameters to get the required size to which they allude. Terribly
      disappointing.
      >
      James
      After playing with this an inordinate amount of time, I found that one
      does need to supply parameters, namely the null parameter of an empty
      string. Try:

      sometop.geometr y('')

      This repacks according to the widgets. Not quite clear from the
      miserable docs, is it?

      James

      Comment

      • James Stroud

        #4
        Re: Tkinter Toplevel geometry

        James Stroud wrote:
        James Stroud wrote:
        >Chris wrote:
        >>Hi,
        >>>
        >>If a user resizes a Toplevel window, or I set a Toplevel's geometry
        >>using the geometry() method*, is there any way to have the geometry
        >>reset to that required for all the widgets?
        >>>
        >>I think I found what I'm looking for in tk itself:
        >>"""
        >>13.3. How can I clear the geometry settings for a toplevel?
        >>If you want to have Tk resize your toplevel to what the toplevel
        >>requires (ie: the user might have resized it, or a widget was
        >>removed), use [wm geometry $toplevel].
        >>"""
        >>[from http://tcl.sourceforge.net/faqs/tk/]
        >>>
        >>>
        >>>
        >>* for instance, if I want to turn of Tkinter's automatic adjustment of
        >>the window to fit all the widgets by doing something like
        >>self.geometry (self.geometry( )), is there any way to undo that?
        >>>
        >>Thanks,
        >>Chris
        >>>
        >>
        >Hi Chris,
        >>
        >I think you are on to something. The equivalent of
        >>
        > [wm geometry $toplevel]
        >>
        >in Tkinter would be
        >>
        > sometop.geometr y()
        >>
        >Or, equivalently,
        >>
        > sometop.wm_geom etry()
        >>
        >Or, calling the underlying tcl/tk interpreter directly
        >>
        > sometop.tk.call ('wm', 'geometry', str(sometop))
        >>
        >Which is redundant, but emphasizes the point: This does not resize the
        >widget as expected nor does it cause the window to resize upon adding
        >new packing slaves--at least for the X11 based Tkinter for mac via the
        >fink debian based package manager.
        >>
        >Really wish things worked according to the docs a lot of the time or
        >that they weren't so poorly written. Perhaps they are implying that
        >you must pass parameters, however they do not explain how one might
        >generate said parameters to get the required size to which they
        >allude. Terribly disappointing.
        >>
        >James
        >
        After playing with this an inordinate amount of time, I found that one
        does need to supply parameters, namely the null parameter of an empty
        string. Try:
        >
        sometop.geometr y('')
        >
        This repacks according to the widgets. Not quite clear from the
        miserable docs, is it?
        >
        James
        Now for the advanced question, how might one bind that to the
        resize/maximize button of the window decorations? I'm guessing with
        protocol, but its way past my bedtime.

        James

        Comment

        • Chris

          #5
          Re: Tkinter Toplevel geometry

          After playing with this an inordinate amount of time, I found that one
          does need to supply parameters, namely the null parameter of an empty
          string. Try:
          >
          sometop.geometr y('')
          >
          This repacks according to the widgets. Not quite clear from the
          miserable docs, is it?

          Wow, that does work. Thank you very much for figuring it out!

          Comment

          • Cameron Laird

            #6
            Re: Tkinter Toplevel geometry

            In article <1174824649.683 426.78990@d57g2 000hsg.googlegr oups.com>,
            Chris <ceball@gmail.c omwrote:
            >
            >After playing with this an inordinate amount of time, I found that one
            >does need to supply parameters, namely the null parameter of an empty
            >string. Try:
            >>
            > sometop.geometr y('')
            >>
            >This repacks according to the widgets. Not quite clear from the
            >miserable docs, is it?
            >
            >
            >Wow, that does work. Thank you very much for figuring it out!
            >
            A TRULY good way to show your thanks for help like this
            is to write up what you learned at the Tkinter Wiki <URL:
            http://tkinter.unpythonic.net/wiki/ >. Note:
            A. You have to log in to edit pages
            on this particular Wiki. If you
            decide to join us, then, you'll
            first need to create an account.

            Read-only visitors can be anony-
            mous, of course.
            B. Major thanks to Jeff Epler for
            maintaining the site, and, in
            particular, for fighting off
            recent vandalism.

            Comment

            • Russell E. Owen

              #7
              Re: Tkinter Toplevel geometry

              In article <1174803181.656 189.303200@l77g 2000hsb.googleg roups.com>,
              "Chris" <ceball@gmail.c omwrote:
              Hi,
              >
              If a user resizes a Toplevel window, or I set a Toplevel's geometry
              using the geometry() method*, is there any way to have the geometry
              reset to that required for all the widgets?
              >
              I think I found what I'm looking for in tk itself:
              """
              13.3. How can I clear the geometry settings for a toplevel?
              If you want to have Tk resize your toplevel to what the toplevel
              requires (ie: the user might have resized it, or a widget was
              removed), use [wm geometry $toplevel].
              """
              ....

              I'm glad you got that figured out.

              Here's a variant question that has driven me crazy...how to create a
              general-purpose variation of toplevel that:
              - can only be resized in one direction and auto-sizes (to fit widgets)
              in the other direction?
              - has a "reasonable " initial size in the resizable direction.

              The first part is easy -- just use the "resizable" method. I've never
              figured out a clean solution to the second question because:
              - tk doesn't allow setting just X or Y size of a toplevel (the geometry
              call requires both or neither)
              - one can use a frame to force the resizable dimension to the desired
              initial value, but to do that you either have to know in advance what
              geometry manager the user is using, or make them pack their widgets into
              a frame inside the toplevel

              I ended up binding to the Configure event, but it's rather messy for
              such a simple-seeming thing. (The really aggravating part is that perl
              can do this directly because it uses C instead of tcl to talk to tk, and
              tk's C interface is more flexible about setting toplevel geometry!).

              -- Russell

              Comment

              • Chris

                #8
                Re: Tkinter Toplevel geometry

                A TRULY good way to show your thanks for help like this
                is to write up what you learned at theTkinterWiki <URL:http://tkinter.unpytho nic.net/wiki/>. Note:
                A. You have to log in to edit pages
                on this particular Wiki. If you
                decide to join us, then, you'll
                first need to create an account.
                I'll do that, yes. I guess I should create a 'Toplevel' page and put
                the information on there? Unless someone can suggest something better.

                I also wonder if I should have posted this question to the tkinter-
                discuss mailing list (see http://tkinter.unpythonic.net/wiki/TkinterDiscuss)
                instead of to comp.lang.pytho n. However, I wasn't aware of that list
                before, and it's not linked to from the python.org 'community' page
                (as far as I can see - and in fact, the python.org pages imply that
                tkinter questions should be asked on comp.lang.pytho n). I'm new to
                tkinter, so it wasn't immediately clear where to get help.

                Comment

                Working...