file access dialog

W

Wouter van Ooijen

I have a tool in Python to which I want to add a small GUI. The tools
currently runs everywhere PySerial is supported. I need a file-access
dialog. What is the preffered way to to this? Is there a
platform-independent file-access dialog available, or should I use the
windows native version when running on windows (and how do I do that)?


Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
Webshop for PICs and other electronics
http://www.voti.nl/hvu
Teacher electronics and informatics
 
F

Fredrik Lundh

Wouter said:
I have a tool in Python to which I want to add a small GUI. The tools
currently runs everywhere PySerial is supported. I need a file-access
dialog. What is the preffered way to to this? Is there a
platform-independent file-access dialog available, or should I use the
windows native version when running on windows (and how do I do that)?

depends on what GUI toolkit you prefer to use.

for Tkinter (which is available on most modern platforms), see "File
Dialogs" on this page:

http://www.pythonware.com/library/tkinter/introduction/x1164-data-entry.htm

the following thread may also be helpful:

http://tinyurl.com/b2zxb

</F>
 
E

Eric Brunel

I have a tool in Python to which I want to add a small GUI. The tools
currently runs everywhere PySerial is supported. I need a file-access
dialog. What is the preffered way to to this? Is there a
platform-independent file-access dialog available, or should I use the
windows native version when running on windows (and how do I do that)?

Tkinter has a file acces dialog available with the same API on all platforms. It is also mapped to the standard dialog on Windows. Since Tkinter is certainly installed by default with Python, if a file dialog is everything you need, you probably don't have to look further.

To use the dialog, just do:

from Tkinter import Tk
from tkFileDialog import askopenfilename
## Tk needs a main window to work, so create one and hide it
root = Tk()
root.withdraw()
## Ask the file name
fileName = askopenfilename(filetypes=[('Python files', '*.py'), ('All files', '*')])
if fileName:
print 'open', fileName
else:
print 'cancelled'
## Over
root.destroy()

HTH
 
W

Wouter van Ooijen

Tkinter has a file acces dialog available with the same API on all platforms. It is also mapped to the standard dialog on Windows.
Since Tkinter is certainly installed by default with Python, if a file dialog is everything you need, you probably don't have to look further.

Great :)


Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
Webshop for PICs and other electronics
http://www.voti.nl/hvu
Teacher electronics and informatics
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,315
Members
47,996
Latest member
LaurenFola

Latest Threads

Top