2012-02-28 177 views
4

我正在使用Windows XP和Python 2.7.2 & Tkinter GUI工具包。我想構建一個簡單的圖形用戶界面,它具有文本字段和「瀏覽」按鈕,可以通過C:\等目錄選擇文件(就像Windows資源管理器一樣)。所選文件將顯示在GUI的文本字段中。希望這是足夠描述性的。使用Python 2.7瀏覽Windows目錄GUI使用Python 2.7

回答

0

我建議你不要使用tkinter,但你使用wxwindows。我之前都用過不同程度的成功(我只是在搞基礎)。如果你決定在這裏使用了wxWindows是一個網站,是非常有用的:http://www.wxpython.org/onlinedocs.php

8

我有別的東西可以幫助你:

## {{{ 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/