Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > tkFileDialog question

Reply
Thread Tools

tkFileDialog question

 
 
Matt Mitchell
Guest
Posts: n/a
 
      11-13-2009
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
 
Reply With Quote
 
 
 
 
r
Guest
Posts: n/a
 
      11-14-2009
Opps, i see you answered your own question

To save you more hours of Googling take a look at these two sites!

#great reference
http://infohost.nmt.edu/tcc/help/pubs/tkinter/

#more in-depth
http://effbot.org/tkinterbook/

you'll want to keep them both under your pillow.
 
Reply With Quote
 
 
 
 
r
Guest
Posts: n/a
 
      11-14-2009
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
 
Reply With Quote
 
r
Guest
Posts: n/a
 
      11-16-2009
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.
 
Reply With Quote
 
Matt Mitchell
Guest
Posts: n/a
 
      11-16-2009




-----------------------------------
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=
[mailtoython-list-bounces+mmitchell=] On
Behalf Of r
Sent: Monday, November 16, 2009 12:16 AM
To: python-
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tkFileDialog Question garyr Python 0 03-16-2011 08:35 PM
RE: tkFileDialog question Matt Mitchell Python 1 11-14-2009 02:33 AM
tkFileDialog, askopenfiles in v2.6 question fransstil Python 1 11-27-2008 12:09 AM
tkFileDialog question jaime.suarez@crossmatch.net Python 3 05-13-2005 05:07 PM
tkFileDialog without a parent window Stephen Boulet Python 2 07-20-2003 01:41 AM



Advertisments