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

[Enhancement] Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. #6655

Open
3 tasks
lee-xp opened this issue Jan 24, 2024 · 29 comments
Labels
Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ enhancement New feature or request Port - TK PySimpleGUI

Comments

@lee-xp
Copy link

lee-xp commented Jan 24, 2024

Type of Issue Bug


Operating System - Windows 10

PySimpleGUI Port (tkinter, Qt, Wx, Web) - tkinter


Versions

Python version 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]

PySimpleGUI Version 4.60.5

GUI Version 8.6.12

pyinstaller Version 3.6.0


Your Experience In Months or Years (optional)

Years Python programming experience 5 years

Years Programming experience overall 40 years+

Have used another Python GUI Framework? (tkinter, Qt, etc) tkinter

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • [X ] Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • [X ] None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [ it's an EXE] Run your program outside of your debugger (from a command line)
  • [ X] Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • [X ] Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • [X ] Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

Detailed Description

Any PySimpleGUI EXEs generated using pyinstaller share the same icon on the taskbar when using PySimpleGUI 4.60.5 (the most recent release). But this issue does not occur with PySimpleGUI 4.57.0 (though it does also happen with the release following 4.57.0 ie 4.58.0). It also occurrs with the version '4.61.0.206 Unreleased' from GitHub.

image

The image shows two different EXEs with different names (which would normally have different and separate icons) sharing the same icon on the taskbar

Running a third PySimpleGUI 4.60.5 EXE, the same thing happens, and all three share the same icon.

This happens with even the simplest of programs:

Code To Duplicate

import PySimpleGUI as sg

layout = [[sg.T(f"PSG version: {sg.version}")]]

window = sg.Window('Taskbar icon issue', layout)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break

window.close()

The pyinstaller command takes the form:
pyinstaller --onefile --noconsole main.py --icon icon.ico
and using earlier versions of pyinstaller does not change anything.

The way I run the EXEs is by double-clicking a shortcut icon on the Desktop.

Screenshot, Sketch, or Drawing


Watcha Makin?

I've used PySimpleGUI in 30 odd programs, and it has been a delight to use: so thank you very much indeed for all the effort you put into creating and maintaining it. Recently I have used PySimpleGUI to build a journey times analyser which accesses Google Maps every hour to analyse traffic on specific routes over the days and weeks. Also an app for exploring embeddings with the OpenAI API.

@pysimpleissue pysimpleissue bot closed this as completed Jan 24, 2024
@lee-xp lee-xp changed the title Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. [Bug] Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. Jan 24, 2024
@pysimpleissue pysimpleissue bot removed Fill issue form or you will be REJECTED You MUST use the supplied template to submit a request. PySimpleGUI Issues Bot Has Detected an Error labels Jan 24, 2024
@pysimpleissue pysimpleissue bot reopened this Jan 24, 2024
Repository owner deleted a comment from pysimpleissue bot Jan 24, 2024
@PySimpleGUI
Copy link
Owner

It's so great to hear from users like yourself that are enjoying using PySimpleGUI! It's hearing that PySimpleGUI is having a positive impact that keeps me motivated.

There's a lot of information in this comment, but I don't have a conclusion I can give you. But maybe by trying some of these ways of looking at the files running you'll be able to piece together what may be happening on your system....


Since seeing your initial post on StackOverflow and asking you come open an issue, I've noticed a different behavior on my taskbar, even though the EXE file I'm running hasn't changed. Very odd that it sent from showing the Python.exe is the program running to now showing my EXE file is.

I wanted to show you how to get information about the EXE file that's running by showing you some screenshots. If you right click the tastkbar, then you see the menu we've all seen....

image

I don't think it's commonly shown that you can then right click the EXE file shown in that menu to see another right click menu

image

This one you can click Properties to get detailed information

image


Combining icons problem... Application ID

I'm wondering the code that sets the Application ID somehow plays a role in this. You'll find it near the end of the PySimpleGUI file.

# Enables the correct application icon to be shown on the Windows taskbar
if running_windows():
    try:
        myappid = 'mycompany.myproduct.subproduct.version'  # arbitrary string
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
    except Exception as e:
        print('Error using the taskbar icon patch', e)

Or if it's entirely an effect that PyInstaller is causing.

Two places to set the Icon and the Title

One thing to be aware of is that there are TWO places icons can be specified in our tests. One is on the EXE file itself that PyInstaller creates for us. The other is when the PySimpleGUI Window is created. It's possible to have them differ, which will be quite confusing.

The Window's title is also specified when the Window is created so there's again a chance for confusion.

Here's a confusing test that I just ran..... I created EXE files using PyInstaller. One I made back in Sept 2023, the other I made last week... Note that the file named simple_popup.exe did not have an icon set when PyInstaller made the EXE. The other program does did.

image
image

When I run the 2 exe files, I see this on my taskbar:

image

When I right click these icons on the taskbar, I see that they claim to be the SAME EXE file....

image

image

Right clicking and choosing Properties provides the exact same information for both programs

image

image

There's clearly some underlying problem that PyInstaller is creating (or maybe it's PySimpleGUI creating it)... regardless it's a side effect of PyInstaller + PySimpleGUI.

@lee-xp
Copy link
Author

lee-xp commented Jan 25, 2024

Thank you very much for the detailed reply. On your first point I have been right-clicking on the taskbar icon and then right-clicking on the exe filename at the top, and then choosing Properties, as you suggested. But as the issue is that two or three applications are all sharing the same idon, I have only one icon to right-click. The Properties window that comes up refers to the first of the two or three apps that are sharing the icon.

I have just repeated the exercise on a Windows 11 machine, recompiling with pyinstaller, and the same thing happens.

I looked at the piece of code that you suggested, and noticed that it is present in the versions which fail, and not present in 4.57.0 which behaves correctly - and when I removed it from version 4.58.0 the problem went away!!!

So - great result - thank you!!

@PySimpleGUI
Copy link
Owner

Thanks for the update! I didn't think about the fact that you're combining the icons..... and thus as you pointed out don't have multiple to choose from.

I'll sneak something into the upcoming release to (hopefully) address this. I appreciate you opening an issue so we could work through it.

@PySimpleGUI PySimpleGUI added Bug Something's not right Port - TK PySimpleGUI enhancement New feature or request and removed Bug Something's not right labels Jan 25, 2024
@PySimpleGUI
Copy link
Owner

Until the enhancement is released, you can control the App ID by making the same call that PySimpleGUI makes. You can do it by adding 1 line of code:

sg.ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('mycompany.myproduct.subproduct.version')

If you want icons to combine, then set the value to be the same in each application. If you don't want them to combine, then change it to a unique value in your code. It can be changed before creating each window if you want to control how each window combines with other windows in the same application.

@lee-xp
Copy link
Author

lee-xp commented Jan 25, 2024

Thanks Mike. That did fix it, and I got two separate icons when running 4.60.5. But interestingly it didn't fix an accompanying feature of the bug - the loss of taskbar icon unless pinned.

I didn't mention the second feature originally because I thought it would obscure the main merging icons issue. But I found that if I had the merging icons issues, it was also the case that the only way I could get the icons to display correctly on the taskbar (after double clicking their desktop shortcut icon) was by pinning them, and if I unpinned them they would revert back to the generic Python icon. This does not happen with 4.57.0: if you double-click a desktop shortcut icon, it appears correctly, and does not need to be pinned for you to see the correct icon.

Removing the lines of code from 4.60.5 not only fixed the merging icons, it also fixed this secondary issue. But the one-line fix does not.

@PySimpleGUI
Copy link
Owner

PySimpleGUI commented Jan 25, 2024

Thanks for the added information.

Are 100% of the executions you're talking about of EXE files created by PyInstaller? You're never running Python files, only EXE files made by PyInstaller?

You may want to try using the psgshortcut application to see if it helps with your desktop shortcut problem. The reason for psgshortcut was to provide better control over icons. How are you creating your shortcuts?

When running, on the taskbar, the icon should be controlled by the PySimpleGUI program itself. Whatever you use when creating your window is what should be shown. However, if icons are merged, then that's going to potentially mix things up. It sounds like there are situations as well where the Python icon is shown.

I'm not sure of the different combinations that may be possible when launching from shortcuts. You can shortcut the .py file, the Python.exe file, a PyInstaller EXE, etc. It would be helpful to get the specific details and screenshots like I provided above.

One reason you may not be seeing problems on earlier versions of PySimpleGUI is that the version may not have the ctypes call above. Given your different scenarios it's looking like a more extensive enhancement involving system settings to provide the ability to control whether or not the App ID is set.

@lee-xp
Copy link
Author

lee-xp commented Jan 26, 2024

Every attempt to put an icon on the taskbar that I have been describing proceeds as follows:
I generate an EXE using pyinstaller. I make a shortcut of the EXE on the desktop (by dragging the EXE icon with the right mouse button, and selecting Create shortcuts here), and I double-click the shortcut to run the EXE, and thus put an icon on the taskbar.

If pyinstaller used 4.58.0 (or 4.60.5), the icon on the taskbar is a generic Python icon (which turns to the correct icon if it is pinned, and reverts back if unpinned). If I then generate another EXE (even of an entirely different program) with pyinstaller using 4.58.0 (or 4.60.5), and create a shortcut and double-click the shortcut, I don't get a new icon on the taskbar (regardless of whether pinned or not). Both EXEs share the same (first) icon just as they would if I had run the same EXE twice.

image
The icon is shared. Here I have not pinned the icon so we see the generic Python icon.

image
The icon is shared. Here I have pinned the icon se we see the icon of the first program.

If however I follow exactly the same process but with pyinstaller using PySimpleGUI 4.57.0 (or 4.60.5 with the lines of code you pointed to removed), the the first icon on the taskbar is correct (not a generic Python icon), as is the second. ie there are, as expected, two correct icons on the taskbar - even though, as in the case below, I am using a very similar EXE.
image

I am wondering if you have access to a Windows setup, because this issue seems to be quite robust, and I would have thought that it was easy to replicate. It happened immediately when I tried it on a different laptop running a different OS (Windows 11 rather than Windows 10).

@PySimpleGUI
Copy link
Owner

make a shortcut of the EXE on the desktop (by dragging the EXE icon with the right mouse button

Give psgshortcut a try to see if it generates any different results.

The icon is shared. Here I have not pinned the icon so we see the generic Python icon.

The icon shown is not the Python icon.... that's the PySimpleGUI icon. The Python icon is rotated 90 degrees from the PySimpleGUI icon. Anytime you see this icon, it means you've not set an icon on your Window and PySimpleGUI is using the built-in default icon. It sounds like you're always setting it, but if you are setting the icon to your own, and ever see the PySimpleGUI icon, then you know something's up with your window creation.

For icons on PySimpleGUI programs, I always bas64 encode them and include them in the Python source code. You'll find examples in all of the PySimpleGUI applications posted in this account. For example in the psgshortcut application, it's in the application source python file, in the main function.

Given that this problem is only happening with PyInstaller, it's worth spending a little time investigating the kinds of problems others have run into and how they got past them.

I am wondering if you have access to a Windows setup

I do, but am very tied up with getting the PySimpleGUI 5 release out the door. Doing my best to provide support to keep you moving ahead.

@lee-xp
Copy link
Author

lee-xp commented Jan 26, 2024

Cool. Thank you. From my perspective this is not urgent at all. I can either keep using v 4.57.0, which works great, or if I really need the 4.60.5 upgrade, I can just use a version with the offending lines remmed out.

Interesting about the rotated icon, I will keep a close lookout for that. And I will check out bas64 encoding them to include in the source file.

Anyway - thanks very much for all your help, and I will leave you to focus on the PySimpleGUI 5 release.

@PySimpleGUI
Copy link
Owner

I almost universally encode and place image files that I may need directly into the PySimpleGUI programs. This stops problems of:

  • Files not being copied
  • Files not being found in the code due to working directory issues

If you're expecting to see an icon, but are seeing the PySimpleGUI one instead, then that's a sign you've got one of the above problems (or others).

The application psgresizer will encode image files into Base64 and place the result on the clipboard so you can simply paste it into your code. It's very handy.

The cases where you're seeing the PySimpleGUI icon when you think you should be seeing something else is an area you can debug or fix and it may get some of the problems you're seeing solved.

@lee-xp
Copy link
Author

lee-xp commented Jan 26, 2024

I will give psgresizer a try. Thanks for the heads-up.

@PySimpleGUI
Copy link
Owner

For the shortcuts you create, regardless of how you create them, take a look at the settings for them.

Here's a shortcut I made by right clicking and dragging.

image

Note the "Start In" field. This is a really important setting because this field is what determines your "working directory". If your EXE is being "unpacked" and saving your icon files in a folder that's different than the working folder, then your PySimpleGUI program may not find the icon file.

In my example, I'm using an icon file and creating my window using:

window = sg.Window('Window Title', layout, icon='icon.ico')

It runs and shows the icon I expect. If I then delete the value of the Starting In field, then it still works fine, I assume because the folder the shortcut is in is the same as where the icon is.

image

image

If I get the folder to C:, then the icon I see is the PySimpleGUI icon, NOT the icon I set when I created the window. Nothing else changed, only the value in the shortcut.

image

image

@lee-xp
Copy link
Author

lee-xp commented Jan 26, 2024

Here are two properties windows for two shortcuts. The one on the left is from 4.57.0, and works perfectly. The one on the right is from 4.58.0, and has the icon merging bug.

image

The two properties windows look identical except for the name of the exe.

@PySimpleGUI
Copy link
Owner

PySimpleGUI commented Jan 26, 2024

If you make the ctypes call with a different value for each EXE file, it still merges them?

Please be careful when talking about "the bug" as there are TWO. I was addressing your shortcut problem. Perhaps another issue should be opened with these two separated.

@PySimpleGUI
Copy link
Owner

PySimpleGUI commented Jan 26, 2024

Thanks Mike. That did fix it, and I got two separate icons when running 4.60.5. But interestingly it didn't fix an accompanying feature of the bug - the loss of taskbar icon unless pinned.

This is why there should be 2 issues. The first one, separate icons, IS fixed by making the provided code be different values for the string for each of your applications:

sg.ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('mycompany.myproduct.subproduct.version')

After that is when you introduced this second problem, the shortcut problem with icons that were incorrect. Let's pull these apart completely.

@lee-xp
Copy link
Author

lee-xp commented Jan 26, 2024

Ok - cool. Because both issues appeared together in 4.58.0, and neither were present in 4.57.0, and because both were fixed by removing the 4 or 5 lines of code that you identified I took the view that they were two sides of the same coin.

@PySimpleGUI
Copy link
Owner

But, they're not. We can revisit this when I've got the capacity to spend more time on it. You've found a solution that works for you using old code and that's fine for now, but will certainly be a problem in the future. I'll give it a pause until I've got more time to spend on it and you've tot time to spend pulling these apart into 2 issues instead of looking at them the same. Thanks for trying the tests and providing data. Sorry I've not been able to get enough time into this to explain it all sufficiently.

@PySimpleGUI PySimpleGUI changed the title [Bug] Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. [Enhancement] Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. Jan 26, 2024
@PySimpleGUI
Copy link
Owner

If you spend some time with the data presented in this issue, I think you would be able to get educated on how shortcuts work and why you were seeing the results you were seeing. There should be all you need to get your code working with the current version of PySimpleGUI, without deleting anything.

I've added an enhancement to enable applications to set the IDs so that they can choose set applications to be the same, or even have different windows within the same application behave as if they are either the same or different applications from an icon combination point of view. It's in the PySimpleGUI 5 release in test now. Hopefully available soon!

@lee-xp
Copy link
Author

lee-xp commented Jan 27, 2024

Ok - cool - though it would be great if later versions could behave as 4.57.0 behaves without needing to change the way that icons or shortcuts are created by the user.

@PySimpleGUI
Copy link
Owner

it would be great if later versions could behave as 4.57.0 behaves

They won't. The brief explanation is that you've got bugs in your code and potentially in how you're packaging your PyInstaller EXE files. There's a backward compatibility issue as well. I understand that you can simply delete the code, but I can't as there are a lot of people relying on that code to get the behavior they're after in their application.

We can work on it together more after the PSG 5 release gets posted if you've not figured it all out. BTW, I'm not saying any of this is easy. It's complicated. There are a lot of libraries involved, operating system behavior, settings, calls, lots of moving parts. We'll get it right one way or another.

image

@lee-xp
Copy link
Author

lee-xp commented Jan 27, 2024

you've got bugs in your code

Not sure I understand this. The Python code is trivial and does virtually nothing. The only other code is a line calling pyinstaller:
pyinstaller --onefile --noconsole main.py --icon icon.ico
Are you saying that this is the culprit?

@PySimpleGUI
Copy link
Owner

The code isn't finding your icon file, which is why you sometimes see the PySimpleGUI icon. That's why I explained the working directory with shortcuts, base64 encoding your icons, etc.

@lee-xp
Copy link
Author

lee-xp commented Jan 28, 2024

The issue occurrs even without using shortcuts: I get exactly the same results when double-clicking the EXE icon in File Explorer as I did when double-clicking a desktop shortcut. I get shared icons on the taskbar. The icon is the PySimpleGUI icon unless I pin it to the taskbar. In that case it is the icon of the first of the two merged EXEs.

If I use PySimpleGUI 4.57.0 (or 4.60.5 with the lines removed) it behaves as expected, with no merged icons.

@PySimpleGUI
Copy link
Owner

The icon is the PySimpleGUI icon unless I pin it to the taskbar

This means the .ico file is not being found. Have you base64 encoded it? I don't know where exactly PyInstaller is decompressing the file to. It's evidently not the same location as the "working directory". If the file you pass is "my_icon.ico", then it needs to be in the working directory, whatever that is set to. There should be some instructions in the PyInstaller docs that discuss how to access the files you've included in the EXE.

Try to get your Python code to retrieve the file size of your .ico file using os.path calls. Get PySimpleGUI entirely out of the picture.

@lee-xp
Copy link
Author

lee-xp commented Jan 28, 2024

Looking again at the bit of code which you mentioned earlier, surely that is the culprit because you are setting every appid to the same fixed string - so no wonder they all share the same icon.

# Enables the correct application icon to be shown on the Windows taskbar
if running_windows():
    try:
        myappid = 'mycompany.myproduct.subproduct.version'  # arbitrary string
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
    except Exception as e:
        print('Error using the taskbar icon patch', e)

@PySimpleGUI
Copy link
Owner

From above this is explained.

image

@lee-xp
Copy link
Author

lee-xp commented Jan 28, 2024

Will the default for the enhancement be that icons do not merge? I think that would be very useful.

@PySimpleGUI
Copy link
Owner

The default behavior will be as it is today. The code is backwards compatible. You will have control, through the PySimpleGUI SDK, of the app ID. In the rely to the comment above, you indicated that the call did fix the problem. This is when you brought up the pinning/shortcut/icon problem.

Let's pause on this until the release is posted and see where things are.

@PySimpleGUI
Copy link
Owner

I would really like to get this issue closed so you can have the results you're looking for... so let me try one more time to summarize and then we can revisit after PSG 5 gets launched. I don't want to have your problem get delayed due to the semi-controlled-chaos that happens after big software releases. I don't know how quickly I'll get back to this and you're closer than you think to being done with this.

Your problems will disappear if you'll:

  • Base64 encode your icon and put it into your source code instead of passing in a .ico file. Please do this.
  • Call the App ID call I provided from each of your applications, passing in a different string for each

Your icon file is not being packaged into your EXE so that your python code can access it. Base64 encoding will remove the need to include the file in your EXE file. Your Python program is not finding the .ico file and I suspect that's because PyInstaller isn't being told to put it into your EXE. This is why you see the default icon on your window when it runs. It needs to be explicitly included as a file if you want to access it at runtime, as a file.

The App ID call we already know fixes the merging problem. You'll have the option of switching to the new call being provided in PySimpleGUI 5, or you can even leave your call setting the APP ID the way you code it now and it will work.

Good luck... I'm sure we'll get there eventually. This is likely your shortest path.

@PySimpleGUI PySimpleGUI added the Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ enhancement New feature or request Port - TK PySimpleGUI
Projects
None yet
Development

No branches or pull requests

2 participants