digi proc <[email protected]> added the comment:
Almost certainly a tkinter bug.
A work around is below. First build a DLL from the following C++ source (and
add a similar function for the 'save' dlg rather than the 'open' dlg):
#include "windows.h"
#include "Commdlg.h"
#include "tchar.h"
extern "C"{
__declspec(dllexport) wchar_t * _cdecl GetOpenFileNamePlus(HWND
Parent,LPCWSTR InitDir,LPCWSTR FilenameIn,LPCWSTR Filter,LPCWSTR DefExt,LPCWSTR
Title)
{
OPENFILENAME OpenFile;
// MessageBox(NULL,Title,L"",MB_OK);
memset (&OpenFile, 0, sizeof(OPENFILENAME));
static wchar_t Filename[MAX_PATH*2];
_tcscpy(Filename,FilenameIn);
OpenFile.lpstrInitialDir=InitDir;
OpenFile.lStructSize = sizeof(OPENFILENAME);
OpenFile.hwndOwner = Parent;
OpenFile.lpstrFile = Filename;
OpenFile.nMaxFile = MAX_PATH*2+10;
OpenFile.lpstrFilter = Filter;
OpenFile.nFilterIndex = 0;
OpenFile.lpstrDefExt=DefExt;
OpenFile.lpstrTitle = Title;
OpenFile.Flags=OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST |
OFN_NOCHANGEDIR;
long Stat=GetOpenFileName(&OpenFile);
if(Stat)
return Filename;
else
return NULL;
}
}
Then in python call it like this, for example:
import ctypes
commdlg=ctypes.windll.commdlg_plus
commdlg.GetOpenFileNamePlus.argtypes= [ctypes.c_void_p, ctypes.c_wchar_p,
ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p]
commdlg.GetOpenFileNamePlus.restype= ctypes.c_wchar_p
s=commdlg.GetOpenFileNamePlus(0, "StartDir", "DefFilename", "Text
files\0*.txt\0Image files\0*.jpg;*.gif\0\0","txt", "Select a file")
----------
nosy: +digiproc
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12219>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com