使用Python 2.7浏览Windows目录GUI使用Python 2.7
问题描述:
我正在使用Windows XP和Python 2.7.2 & Tkinter GUI工具包。我想构建一个简单的图形用户界面,它具有文本字段和“浏览”按钮,可以通过C:\等目录选择文件(就像Windows资源管理器一样)。所选文件将显示在GUI的文本字段中。希望这是足够描述性的。使用Python 2.7浏览Windows目录GUI使用Python 2.7
答
看看这个(未经测试):http://www.java2s.com/Code/Python/GUI-Tk/SimpleEditor.htm您可能只需添加'打开'对话框,但使用Tkinter文档应该很简单。
答
我建议你不要使用tkinter,但你使用wxwindows。我之前都用过不同程度的成功(我只是在搞基础)。如果你决定在这里使用了wxWindows是一个网站,是非常有用的:http://www.wxpython.org/onlinedocs.php
答
我有别的东西可以帮助你:
## {{{ http://code.activestate.com/recipes/438123/ (r1)
# ======== Select a directory:
import Tkinter, tkFileDialog
root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')
if len(dirname) > 0:
print "You chose %s" % dirname
# ======== Select a file for opening:
import Tkinter,tkFileDialog
root = Tkinter.Tk()
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
if file != None:
data = file.read()
file.close()
print "I got %d bytes from this file." % len(data)
# ======== "Save as" dialog:
import Tkinter,tkFileDialog
myFormats = [
('Windows Bitmap','*.bmp'),
('Portable Network Graphics','*.png'),
('JPEG/JFIF','*.jpg'),
('CompuServer GIF','*.gif'),
]
root = Tkinter.Tk()
fileName = tkFileDialog.asksaveasfilename(parent=root,filetypes=myFormats ,title="Save the image as...")
if len(fileName) > 0:
print "Now saving under %s" % nomFichier
## end of http://code.activestate.com/recipes/438123/ }}}
这里是我得到了它从网站:http://code.activestate.com/recipes/438123-file-tkinter-dialogs/