tkFileDialog question

Discussion in 'Python' started by Matt Mitchell, Nov 13, 2009.

  1. Hi,

    This is my first attempt to write a script with any kind of gui. All I
    need the script to do is ask the user for a directory and then do stuff
    with the files in that directory. I used tkFileDialog.askdirectory().
    It works great but it pops up an empty tk window. Is there any way to
    prevent the empty tk window from popping up? Here's the code:


    import tkFileDialog

    answer = tkFileDialog.askdirectory()

    if answer is not '':
    #do stuff

    Thanks!
    Matt
     
    Matt Mitchell, Nov 13, 2009
    #1
    1. Advertising

  2. Matt Mitchell

    r Guest

    r, Nov 14, 2009
    #2
    1. Advertising

  3. Matt Mitchell

    r Guest

    Opps: And here i go making a clown of myself again...

    import Tkinter as tk
    from tkFileDialog import askdirectory
    import os

    root = tk.Tk()
    root.withdraw()

    folder = askdirectory()
    #make sure to do this somewhere that will always execute!
    root.destroy()
    if folder:
    print os.listdir(folder)

    root.mainloop()

    r... just another would be language designer
     
    r, Nov 14, 2009
    #3
  4. Matt Mitchell

    r Guest

    Matt,

    There is also a nice thing you need to know about Python if you
    already do not know. That is the fact that all empty collections bool
    to False. This makes Truth testing easier.

    >>> bool([])

    False
    >>> bool('')

    False
    >>> bool({})

    False
    >>> bool([1])

    True
    >>> bool([[]])

    True
    >>> bool(' ')

    True

    any empty collection, string, or 0 always bools to False.
     
    r, Nov 16, 2009
    #4
  5. -----------------------------------
    The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you.

    -----Original Message-----
    From: python-list-bounces+mmitchell=
    [mailto:python-list-bounces+mmitchell=] On
    Behalf Of r
    Sent: Monday, November 16, 2009 12:16 AM
    To:
    Subject: Re: tkFileDialog question

    Matt,

    There is also a nice thing you need to know about Python if you
    already do not know. That is the fact that all empty collections bool
    to False. This makes Truth testing easier.

    >>> bool([])

    False
    >>> bool('')

    False
    >>> bool({})

    False
    >>> bool([1])

    True
    >>> bool([[]])

    True
    >>> bool(' ')

    True

    any empty collection, string, or 0 always bools to False.
    --
    http://mail.python.org/mailman/listinfo/python-list



    Thank you both for all the help. Your suggestions have helped clean up
    a bunch of my code.

    Thanks!
    Matt
     
    Matt Mitchell, Nov 16, 2009
    #5
    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. Stephen Boulet

    tkFileDialog without a parent window

    Stephen Boulet, Jul 3, 2003, in forum: Python
    Replies:
    2
    Views:
    511
    klappnase
    Jul 20, 2003
  2. tkFileDialog question

    , May 12, 2005, in forum: Python
    Replies:
    3
    Views:
    413
  3. fransstil
    Replies:
    1
    Views:
    588
  4. Matt Mitchell

    RE: tkFileDialog question

    Matt Mitchell, Nov 13, 2009, in forum: Python
    Replies:
    1
    Views:
    487
  5. garyr

    tkFileDialog Question

    garyr, Mar 16, 2011, in forum: Python
    Replies:
    0
    Views:
    250
    garyr
    Mar 16, 2011
Loading...

Share This Page