在非gui应用程序中使用对话框最方便的方法是什么?

时间:2013-03-19 22:02:19

标签: python windows user-interface

我正在编写一个excel-add编程,我不需要主窗口和所有闪亮的小部件/工具包,但我需要对话框。

这是我尝试创建一个(使用pywin32):

import win32ui, win32con

def openFileDialog(extensions = None, multi = False):
    """open a Windows File 'Open' Dialog. returns a list of path of files selected by user.

    Keyword arguments:
    extensions (default None) - a list or tuple containing (description, ext) 
    pair of acceptable files.
      ext can be a string - i.e) '*.txt', or a list or tuple of many strings ['*.txt', '*.htm']
      description is a string describing corresponding ext. 

    multi - (default False) True to allow user to select more than one files. 
    """

    openFlags = win32con.OFN_OVERWRITEPROMPT|win32con.OFN_FILEMUSTEXIST
    if multi:
        openFlags|=win32con.OFN_ALLOWMULTISELECT

    dlg = win32ui.CreateFileDialog(1,
                                   None,
                                   None,
                                   openFlags,
                                   extensionFilterString(extensions))

    if dlg.DoModal()!=win32con.IDOK:
        return None

    return dlg.GetPathNames()
虽然它们起作用,但我认为这真的不是pythonic。我看了一下pyside,他们有QFileDialog - 但它需要QApplication,好像Qapplication接管主循环。我不认为我需要所有的麻烦,我真的不知道python gui编程。在python中打开文件对话框最方便的方法是什么?

0 个答案:

没有答案