dummy tk windows

Discussion in 'Python' started by Elaine Jackson, Sep 16, 2004.

  1. When I use a function from tkFileDialog outside of a tk GUI context, it creates
    a "dummy" tk window. It would be nice to know how to close these windows
    programmatically. TIA

    Peace
     
    Elaine Jackson, Sep 16, 2004
    #1
    1. Advertising

  2. Elaine Jackson

    Paul Miller Guest

    On Thu, 16 Sep 2004 18:08:12 +0000, Elaine Jackson wrote:

    > When I use a function from tkFileDialog outside of a tk GUI context, it
    > creates a "dummy" tk window. It would be nice to know how to close these
    > windows programmatically. TIA
    >


    IIRC, you can't close them without terminating the tcl interpreter (doing
    so destructs the implicitly created Tk object you instantiated when you
    used the tkFileDialog function). However, you can hide it with:

    import Tkinter
    import tkFileDialog

    root = Tkinter.Tk()
    root.withdraw()
    fileOpen = tkFileDialog.Open()
    fileOpen.show()

    HTH
     
    Paul Miller, Sep 17, 2004
    #2
    1. Advertising

  3. "Paul Miller" <> wrote in message
    news:p...
    <snip> HTH

    It did. Thank you. I made a wrapper for this stuff that I'll include here for
    the benefit of anyone who may be following the discussion from the sidelines.

    Peace

    def dialog(className):
    from Tkinter import Tk
    from tkFileDialog import Open,SaveAs,Directory
    Tk().withdraw()
    name = eval(className)().show()
    if className=='Directory': return name
    mode = (className=='Open' and 'r') or (className=='SaveAs' and 'w')
    return file(name,mode)
     
    Elaine Jackson, Sep 17, 2004
    #3
  4. On Fri, 17 Sep 2004 09:19:26 GMT, rumours say that "Elaine Jackson"
    <> might have written:

    >"Paul Miller" <> wrote in message
    >news:p...
    ><snip> HTH
    >
    >It did. Thank you. I made a wrapper for this stuff that I'll include here for
    >the benefit of anyone who may be following the discussion from the sidelines.
    >
    >Peace
    >
    >def dialog(className):
    > from Tkinter import Tk
    > from tkFileDialog import Open,SaveAs,Directory
    > Tk().withdraw()
    > name = eval(className)().show()
    > if className=='Directory': return name
    > mode = (className=='Open' and 'r') or (className=='SaveAs' and 'w')
    > return file(name,mode)
    >


    Elaine,

    """eval(className)""" is generally insecure. Another (more secure and
    direct) idea would be to """import tkFileDialog""" and then use
    """getattr(tkFileDialog, className)""" instead.
    --
    TZOTZIOY, I speak England very best,
    "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek
     
    Christos TZOTZIOY Georgiou, Sep 29, 2004
    #4
    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. shumon
    Replies:
    1
    Views:
    11,791
    Jim Wu
    Sep 24, 2003
  2. lonelyplanet999

    Dummy perl programming question

    lonelyplanet999, Aug 13, 2003, in forum: Perl
    Replies:
    3
    Views:
    2,124
  3. tuxedo
    Replies:
    4
    Views:
    738
    Carl Prothman [MVP]
    Aug 18, 2003
  4. Nuno Esculcas

    Dummy question

    Nuno Esculcas, Nov 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    383
    Nuno Esculcas
    Nov 15, 2003
  5. Curt_C [MVP]
    Replies:
    3
    Views:
    5,167
Loading...

Share This Page