2012-02-28 14 views
4

私はPython 2.7.2でWindows XPを使用しています& Tkinter GUIキット。テキストフィールドと「Browse」ボタンがあるシンプルなGUIを構築して、C:\(Windowsエクスプローラのような)のようなディレクトリからファイルを選択したいと考えています。選択したファイルは、GUIのテキストフィールドに表示されます。これは十分記述的であることを望みます。Python 2.7を使用してWindowsディレクトリのGUIをブラウズする

答えて

0

tkinterは使用せず、wxwindowsを使用することをお勧めします。私は前に両方のレベルを成功させて使用しました(私はちょうど基本について悩んでいました)。あなたは、ここでのwxWindowsを使用することを決定しない場合は本当に便利ですウェブサイトです:http://www.wxpython.org/onlinedocs.php

8

私はあなたを助けるかもしれない何か他のものがあります:http://code.activestate.com/recipes/438123-file-tkinter-dialogs/

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

をここで私からそれを得たウェブサイトがあります

関連する問題