Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show image without cmd.exe #8409

Closed
pythondever opened this issue Sep 23, 2024 · 2 comments
Closed

How to show image without cmd.exe #8409

pythondever opened this issue Sep 23, 2024 · 2 comments

Comments

@pythondever
Copy link

pythondever commented Sep 23, 2024

What did you do?

I'm using Pillow display image in source code is normal but when display in build after code display image has a console cmd.exe

What did you expect to happen?

I want to hide cmd.exe

What actually happened?

What are your OS, Python and Pillow versions?

  • OS: windows
  • Python: 3.8.10
  • Pillow: 8.0.0

demo code:

show_image = Image.fromqpixmap(item.pixmap())
show_image.show()
@nulano
Copy link
Contributor

nulano commented Sep 23, 2024

Duplicate of #7789.
This was fixed in Pillow 10.3.0: 373c62e

If you can't upgrade, you should be able to run the following code before calling show() as a workaround to replace the default image viewer in older Pillow with the one from Pillow 10.3.0:

from PIL import ImageShow

class MyViewer(ImageShow.Viewer):
    format = "PNG"
    options = {"compress_level": 1, "save_all": True}

    def get_command(self, file: str, **options: Any) -> str:
        return (
            f'start "Pillow" /WAIT "{file}" '
            "&& ping -n 4 127.0.0.1 >NUL "
            f'&& del /f "{file}"'
        )

    def show_file(self, path: str, **options: Any) -> int:
        """
        Display given file.
        """
        if not os.path.exists(path):
            raise FileNotFoundError
        subprocess.Popen(
            self.get_command(path, **options),
            shell=True,
            creationflags=getattr(subprocess, "CREATE_NO_WINDOW"),
        )  # nosec
        return 1

ImageShow.register(MyViewer, 0)

@radarhere radarhere changed the title how to show image without cmd.exe How to show image without cmd.exe Sep 23, 2024
@pythondever
Copy link
Author

pythondever commented Sep 24, 2024

solved!, good solution for users who cannot upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants