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

Showing an image opens a console #7789

Closed
Vermylion opened this issue Feb 9, 2024 · 3 comments · Fixed by #7791
Closed

Showing an image opens a console #7789

Vermylion opened this issue Feb 9, 2024 · 3 comments · Fixed by #7791
Labels

Comments

@Vermylion
Copy link

What did you do?

Tried opening an image using image.show() with a .pyw file.

What did you expect to happen?

Logically, no cmd console should pop up, as the file is no console.

What actually happened?

PIL opens up a console when launching image viewer, presumably Windows Viewer (default viewer).

What are your OS, Python and Pillow versions?

  • OS: Windows 10/11
  • Python: 3.12
  • Pillow: 10.2.0

To Replicate the Issue

Have a file with no console extension: main.pyw
Launch python file outside of an environment, IDE, or a console (cmd). Launch it, for example, from the Windows File Explorer.

from PIL import Image

img_path = 'your_image_path.png' # Replace with your image path

img = Image.open(img_path)

img.show()

Potential Solution

From what I've seen and understood, the issue is caused in ImageShow.py, show_file() line 116 with os.system(self.get_command(path, **options)). This line of code appears to be opening a new console if the file is ran with no console. However, it can be easily fixed by replacing os by subprocess: subprocess.call(self.get_command(path, **options), shell=True, creationflags=subprocess.CREATE_NO_WINDOW) (has been tested and works).

@radarhere
Copy link
Member

Hi. Would you like to create a PR with your solution?

@radarhere
Copy link
Member

I've created PR #7791 with your solution, except with subprocess.Popen() instead of subprocess.call(), to prevent blocking.

@Vermylion
Copy link
Author

Hi, thanks for making the PR!

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

Successfully merging a pull request may close this issue.

2 participants