Tkinter pack bug in Python 2.3

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

    Tkinter pack bug in Python 2.3


    The compact form of pack behaves differently (and I believe incorrectly)
    compared to the long form. The following two scripts demonstrate it, at
    least on this interpreter:
    Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
    [GCC 3.3.1 (cygming special)] on cygwin


    # First script, no bug

    # I want a canvas inside a frame inside a toplevel, with the canvas
    # filling the toplevel even as I resize the window. This does it.

    from Tkinter import *

    root = Tk()
    frame = Frame(root, bg="lightBlue" )
    frame.pack(side =TOP, expand=1, fill=BOTH)
    canvas = Canvas(frame, bg="lightGreen" )
    canvas.pack(sid e=TOP, expand=1, fill=BOTH)

    mainloop()





    # Second script, bug

    # I want a canvas inside a frame inside a toplevel, with the canvas
    # filling the toplevel even as I resize the window. This doesn't do
    # it, and instead makes the canvas a sibling of the frame, instead of
    # a child. (Try resizing the toplevel and you'll see.) Why?

    from Tkinter import *

    root = Tk()
    frame = Frame(root, bg="lightBlue") .pack(side=TOP, expand=1, fill=BOTH)
    canvas = Canvas(frame, bg="lightGreen" ).pack(side=TOP , expand=1, fill=BOTH)

    mainloop()



    Frank (filologo disneyano) http://www-lce.eng.cam.ac.uk/~fms27/


  • Peter Otten

    #2
    Re: Tkinter pack bug in Python 2.3

    Frank Stajano wrote:
    [color=blue]
    >
    > The compact form of pack behaves differently (and I believe incorrectly)
    > compared to the long form. The following two scripts demonstrate it, at[/color]

    There is no "compact form", see below.

    [...]
    [color=blue]
    > # Second script, bug
    >
    > # I want a canvas inside a frame inside a toplevel, with the canvas
    > # filling the toplevel even as I resize the window. This doesn't do
    > # it, and instead makes the canvas a sibling of the frame, instead of
    > # a child. (Try resizing the toplevel and you'll see.) Why?
    >
    > from Tkinter import *
    >
    > root = Tk()
    > frame = Frame(root, bg="lightBlue") .pack(side=TOP, expand=1, fill=BOTH)[/color]

    You are assigning the result of the pack() method, i. e. None, to frame
    here, and consequently Canvas is constructed with None instead of a Frame
    instance as the first argument.
    [color=blue]
    > canvas = Canvas(frame, bg="lightGreen" ).pack(side=TOP , expand=1,
    > fill=BOTH)
    >
    > mainloop()[/color]

    Peter

    Comment

    • Michael Peuser

      #3
      Re: Tkinter pack bug in Python 2.3


      "Frank Stajano" <fms27@cam.ac.u k

      Old Perl programmer, hmm... ;-)

      Kindly
      MichaelP


      Comment

      Working...