GetSaveFileName.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import win32gui, win32con, os
  2. filter='Python Scripts\0*.py;*.pyw;*.pys\0Text files\0*.txt\0'
  3. customfilter='Other file types\0*.*\0'
  4. fname, customfilter, flags=win32gui.GetSaveFileNameW(
  5. InitialDir=os.environ['temp'],
  6. Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
  7. File='somefilename', DefExt='py',
  8. Title='GetSaveFileNameW',
  9. Filter=filter,
  10. CustomFilter=customfilter,
  11. FilterIndex=1)
  12. print('save file names:', repr(fname))
  13. print('filter used:', repr(customfilter))
  14. print('Flags:', flags)
  15. for k,v in list(win32con.__dict__.items()):
  16. if k.startswith('OFN_') and flags & v:
  17. print('\t'+k)
  18. fname, customfilter, flags=win32gui.GetOpenFileNameW(
  19. InitialDir=os.environ['temp'],
  20. Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
  21. File='somefilename', DefExt='py',
  22. Title='GetOpenFileNameW',
  23. Filter=filter,
  24. CustomFilter=customfilter,
  25. FilterIndex=0)
  26. print('open file names:', repr(fname))
  27. print('filter used:', repr(customfilter))
  28. print('Flags:', flags)
  29. for k,v in list(win32con.__dict__.items()):
  30. if k.startswith('OFN_') and flags & v:
  31. print('\t'+k)