Tkinter Button dimensions

Discussion in 'Python' started by Elaine Jackson, Jul 1, 2004.

  1. In the script I'm writing, there's a Tkinter Button that contains a square image
    at some times and is blank at other times. Is there a smart way to make its
    dimensions stay the same throughout all this? Any help will be greatly
    appreciated.

    Peace
     
    Elaine Jackson, Jul 1, 2004
    #1
    1. Advertising

  2. Elaine Jackson

    Eric Brunel Guest

    Elaine Jackson wrote:
    > In the script I'm writing, there's a Tkinter Button that contains a square image
    > at some times and is blank at other times. Is there a smart way to make its
    > dimensions stay the same throughout all this? Any help will be greatly
    > appreciated.


    Two solutions come to mind:
    - specifying a width and a height for the button; a bit awkward, since the unit
    taken for the dimensions depends on what is displayed in the button (pixels for
    an image; characters for text). And configuring the button size when nothing is
    displayed in it seems to take dimensions in characters, which is not suitable
    for what you want to do.
    - create an empty image of the same size of the existing one and set this image
    for the button when it should be empty. Example:

    from Tkinter import *
    root = Tk()
    img = PhotoImage(width=50, height=50)
    Button(root, image=img).pack()
    root.mainloop()

    This may be the best solution for what you want to do.

    HTH
    --
    - Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
     
    Eric Brunel, Jul 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Assaf
    Replies:
    0
    Views:
    378
    Assaf
    May 10, 2004
  2. =?Utf-8?B?cGJ1bQ==?=

    GDI+ - limits for pixel dimensions in a bitmap object

    =?Utf-8?B?cGJ1bQ==?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    369
    =?Utf-8?B?cGJ1bQ==?=
    Jun 18, 2004
  3. Major Johnson

    Programmatically Resize Frameset Dimensions

    Major Johnson, Jul 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,396
    Kevin Spencer
    Jul 14, 2004
  4. Scott Reynolds

    Calculate image dimensions

    Scott Reynolds, Aug 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    492
    Scott Reynolds
    Aug 29, 2004
  5. Kenny
    Replies:
    1
    Views:
    676
    Travis Murray
    Dec 13, 2004
Loading...

Share This Page