This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author digiproc
Recipients brian.curtin, digiproc, hfischer, loewis, ned.deily, terry.reedy
Date 2011-07-12.13:17:23
SpamBayes Score 9.3289174e-08
Marked as misclassified No
Message-id <1310476644.82.0.00380178931372.issue12219@psf.upfronthosting.co.za>
In-reply-to
Content
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")
History
Date User Action Args
2011-07-12 13:17:24digiprocsetrecipients: + digiproc, loewis, terry.reedy, ned.deily, brian.curtin, hfischer
2011-07-12 13:17:24digiprocsetmessageid: <1310476644.82.0.00380178931372.issue12219@psf.upfronthosting.co.za>
2011-07-12 13:17:24digiproclinkissue12219 messages
2011-07-12 13:17:23digiproccreate