The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

Paul St George email at paulstgeorge.com
Tue May 29 11:40:57 EDT 2018


Thank you. For the advice, and for the new word 'monkeypatch'.


On 27/05/2018 23:58, Cameron Simpson wrote:
> On 27May2018 20:15, Paul St George <email at paulstgeorge.com> wrote:
>> This is very helpful indeed, thank you. Awe-inspiring.
>>
>> It occurred to me that I could edit the PIL/ImageShow.py, replacing 
>> ‘xv’ (in five places) with the utility of my choice and using 
>> ‘executable’ as the command.
>>
>> Or, is this just not done?
>
> It becomes a maintenance problem.
>
> Alternatively you could:
>
> Just write your own show function which accepts an Image and displays 
> it with your program of choice. You might need to write some 
> equivalent code which saves the Image to a file first, and removes it 
> afterwards.
>
> You could copy the show() code into a function of your own (i.e. in 
> your own codebase) modify that to suit, then monkeypatch the class:
>
>  Image.show = your_personal_show_function
>
> when your programme starts. That way the code changes are not in the 
> PIL code.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
>

-- 
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302




More information about the Python-list mailing list