Pysimplegui: [ Question] * MAC USERS * is no_titlebar working for you?

Created on 28 Oct 2020  ·  30Comments  ·  Source: PySimpleGUI/PySimpleGUI

Type of Issues (Enhancement, Error, Bug, Question)

Bug / Problem with tkinter

Does no_titlebar work?
Does tooltips work?

Operating System

Mac

Python version

3.6+

PySimpleGUI Port and Version

This is where things get important to understand.

I would like to know from someone running 8.610 and also someone NOT running 8.6.10.

I'm trying to understand if this is specific to 8.6.10.

You can get the detailed tkinter version by adding this line to your code:

print(sg.tkinter.Tcl().eval('info patchlevel'))

Description of Problem / Question / Details

I recall no_titlebar issues on the Mac and would like to make a concerted effort to fix them if there's a problem. I really need some solid help from a couple of Mac users.

I need someone that can do these:

  • Get accurate tkinter version info (I code is provided)
  • Being able to try a couple of potential fixes when posted to GitHub

Code To Duplicate

A short program that isolates and demonstrates the problem (i.e. please don't paste a link to your 400 line program.... instead paste your 10 line program in full).

Yes, it is a pain to narrow down problems, but it's part of the debugging process. Help me help you by providing something that can be executed so that work on getting you a fix or a workaround can immediately begin.

This pre-formatted code block is all set for you to paste in your bit of code:

print(sg.tkinter.Tcl().eval('info patchlevel'))

You can test to see if you've got problems by running:

import PySimpleGUI as sg

sg.popup_no_titlebar('This should not have a titlebar')

image

Mac Specific Issue community input desired help wanted

All 30 comments

Part of the problem of debugging this in the past is that there was never really a proper table made to aid in debugging. There are 3 variables at play:

  1. PySimpleGUI version
  2. tkinter version
  3. MacOS version

Much of the time, it's been the tkinter version that's been the focus. I'm unsure if tkinter is responsible for all of the problems seen.

Here is my breakdown:

PySimpleGUI v4.30.0
tkinter v8.6
MacOS 10.15.7

I also want to mention that I use Homebrew for my python binaries.

Screen Shot 2020-10-28 at 8 10 31 PM

Edit:

Python v3.8.1

macOS High Sierra Version 10.13.6
PySimpleGUI Version 4.30.0.12
tcl ver = 8.6 tkinter version = 8.6
tcl detailed version = 8.6.10
Python Version 3.8.6

And... it works!
it_works

edit: The environment that gave me the fewest headaches regarding tkinter:

Homebrew -> brew install tcl-tk
Homebrew -> brew install pyenv -> Python (see below)

env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PYTHON_CONFIGURE_OPTS="--enable-framework --with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
  pyenv install 3.8.6

pyenv global 3.8.6

and to make this my default python:

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

I followed all the steps listed by @norambna and I got it to work for me. It was a bit cumbersome to jump through all the hoops though.

Python v3.8.6
PySimpleGUI v4.30.0
tkinter v8.6
MacOS 10.15.7
pyenv v1.2.21
tcl-tk v8.6.10

image

I'm glad it helped! I know I had a hard time till finding a solution to all my macOS/tkinter problems. This won't solve all tkinter issues, but it's clearly the best way to work with it on macOS.

Does it appear that tkinter version 8.6.10 is what fixes this problem?

If all versions have problems except 8.6.10, then I could check for that version and apply the "fix" only to non-8.6.10 releases.

What I've been really confused about is if this is a recent problem or has no-titlebar never worked on the Mac. It seems odd that it would have never worked, but it's difficult to tell for sure.

The "fix" I've seen is potentially going to break other stuff which is why I've hesitated adding it to the code.

These steps are pretty ugly so I think that I've got to do something about this. Users can't be expected to go through this much trouble. I'll pull together a release for GitHub with the fix that checks the tkinter version number and only applies it when the version is not 8.6.10.

Does it appear that tkinter version 8.6.10 is what fixes this problem?

For me, yes. 8.6.10 solves a ton of issues.

I just posted 4.30.0.13 that contains a patch if the version is less than 8.6.10.

If this "fixes" the problem, then I want to try one more patch. This new patch clears the wm_overrideredirect flag after first setting it.

root.wm_overrideredirect(True)
root.wm_overrideredirect(False)

What I would like to try next is to set it to True again so that the operation is a True False True. The idea here is that for some systems, it may be working correctly if the value is set to True. What I don't want to do is break all of the installs where it is functioning correctly today and setting it to True again may provide a workaround that does the right thing on all versions of tkinter on Mac.

You will see this message printed on the console if the patch is applied:
* Applying Mac no_titlebar patch *

One way to test this is through the test harness which will save you from having to write code to call and test popups. One of the tabs in the test harness (invoked by running PySimpleGUI.py file or calling sg.main()) is used to test popups.

image

This will let you quickly check both the no-titlebar window as well as by calling popups with a titlebar.

It may be difficult to spot because the background is the same as your test window. If you click No Titlebar button, you'll see this little window

image

I hope this fixes the non 8.6.10 version as well as not running on 8.6.10+. If it doesn't I'll quickly put together another test to see if setting it back again works.

If we get this nailed down, I'll get the release posted to PyPI as a high-priority release.

I need some help from Macs users

There was a patch posted to GitHub to try and get around this problem of no titlebar. I need to understand if:

  • The patch fixes the problem on non 8.,6.10 systems
  • The patch doesn't cause problems with 8.6.10

Can someone download the GitHub version and try it?

I would love to help. I have everything set up as far as the tkinter version, but I'm not sure how to import the 4.30.0.13 version of PySimpleGUI. How exactly do you download that version and use it?

It should be with same patch in most update version.

Upgrading from GitHub Using PySimpleGUI

Not sure what to do about this patch. I'm pulling together a release to PyPI now and without it being properly tested on a Mac, I'm going to have to pull the code from the release. I would rather release a known problem than potentially a whole new set of problems. Of course, my preference is to get this fixed for good and post to PyPI.

If there are Mac users that are capable of running a few tests, I, and I'm guessing a few of your fellow Mac users, would appreciate the help.

I don't want to delay the release while waiting for Mac users to test the new code. So, I've added more code to control when the patch is executed. I can't just toss this "fix" out there and potentially break existing Mac users. Well, technically I could, but I prefer not to create problems for users that have working code today.

To enable the patch for no-titlebar windows on a Mac call set_options with the parameter enable_mac_notitlebar_patch set to True.

    sg.set_options(enable_mac_notitlebar_patch=True)

The patch will cause an additional call when a no-titlebar Window is created:

root.wm_overrideredirect(False)

The patch will only execute on Macs that are running tkinter versions < 8.6.10.

By default the patch is disabled. You have to take affirmative action in order to get the patch by calling set_options.

This code is in version 4.30.0.26 and is on GitHub now. It will be released in version 4.31.0 shortly.

Like I said before, I would be willing to run any tests on your previous patch. I have two different mac devices running different versions of the OS. I am also running various versions of python and tcl/tk.

Apologies if this is a dumb question, but how do I install these versions (4.30.0.13 or 4.30.026)? I usually use pip install, but if I have do something different then I need a bit of guidance to help you out.

4.31.0 was posted to PyPI earlier today. You can pip install it like you have other versions.

Add the line of code in the previous post and you'll be running with the patch enabled.

 sg.set_options(enable_mac_notitlebar_patch=True)

You can install GitHub versions using the sg.main() user interface by clicking the red button that says "Upgade". 4.31.0 is the Current version on GitHub and the one that's been released to PyPI.

I did a few different tests on different versions of tcl/tk (8.5.9, 8.6.8, 8.6.10) and I found that the original code
image
will make the titlebar appear to be disabled, but I can click on the minimize or x button. If I minimize it and then bring it back up then the titlebar is completely disabled. This happens on both 8.5.9 and 8.6.8. Everything works good for 8.6.10. (like mentioned in previous comments)

Next, I tried to run it with your patch.
image
What ended up happening was the titlebar was active and both the minimize and the x buttons worked, and when I minimized it and brought the window back up it would then be disabled, similar to what I mentioned above.

So the issues are still happening with versions 8.6.8 and lower.

Here was the original code using tkinter to get a no-titlebar draggable window.
image
I found this code when I was searching around to try and solve this issue of trying to hide the titlebar. This is using tcl/tk 8.6.8 or below
https://stackoverflow.com/questions/29641616/drag-window-when-using-overrideredirect

Versions
MacOS: 10.15.7
PySimpleGUI: 4.31.0 latest
Python: 3.8.1, 3.8.6, 3.9.0

For tcl/tk 8.6.8 or lower
neither patch or original example work

Did you see a message on the console that the patch was being applied?

What's odd about the tests is that the technique I'm using to achieve the no-titlebar is one that was previously posted here. It's basically to repeat the override but with a False value. It's also odd that there's a locking up behavior that appears to be new.

Can you make sure that you see this message:

'* Applying Mac no_titlebar patch *

If you do not see this message, then the patch was not applied.

It would be helpful if you printed the version of PySimpleGUI in addition to printing the version of tkinter just to be sure we're working with the combination of variables we think we are.

I'm suspecting more and more that the MacOS has a role to play here as well. I didn't hear of this no-titlebar problem and the problem with tooltips until earlier this year. These features were some of the first to be released in PySimpleGUI, and yet there was no report of problems with these features until not that long ago.

The drag-anywhere part of this hasn't been discussed before and is new data. Can we focus on just getting the no-titlebar code tested and working?

The "fix" for this may very well end up being that Mac users must run tkinter 8.6.10. I'm spending too much time and energy on a problem that's clearly a bug in the Mac software. Not being able to test the code is making this a nearly impossible task to get completed.

I've been here once before with the tk button bug, which was a known problem for over 6 years and yet wasn't fixed. The fix for that was to add support for ttk buttons to PySimpleGUI. It was a lot of work, but ultimately allowed Mac users to use PySimpleGUI. Unlike that bug, this one appears to have caught the attention of the tkinter / Mac developers and it was fixed in 8.6.10. That means there's a path for Mac users to follow that they can get to on their own, without these kinds of hacks and workarounds being added to the code.

I like my Mac users, but it's hard to justify investing too much into supporting that platform when the number of users is tiny. I don't believe installs have ever broken 10% for the Mac.

image

Yea it seems like a huge hassle for a small group of users. I just downloaded macOS v11 (new this week), and there seems to be some different behavior. For instance, the minimize and x buttons are completely disabled now unlike my previous post.

One thing I also noticed with tkinter on macOS v11 is that for tk/tcl v8.5.9, I only need to say root.overrideredirect(True) for no titlebar, but when I try to do the same on tk/tcl v8.6.8 it doesn't work. I still need to do

root.overrideredirect(True)
root.overrideredirect(False)

in order to get it to work.

FYI, I was getting the log message saying that the patch was being applied. Also the version of PySimpleGUI I was using was 4.31.0 Released 13-Nov-2020.

I don't mind supporting a small group of users with some code specific to the Mac platform. The problem is that it's been a moving target. I've not been able to find a stable footing recently. Things were seemingly going great after Mac users switched to installing from Python.org instead of Homebrew. That got everyone away from releases that had trouble with buttons and tables. But then something seems to have changed. I think that something was likely the Mac OS.

As I mentioned earlier, there are 3 variables at play. There is the tkinter version, the PySimpleGUI version and the MacOC version. I'm tossing out the Python version from that list because while tkinter is packaged with Python and can differ from one release of Python to another, as long as we're tracking the tkinter version, then the Python version doesn't matter. I don't have a handle on the outcome is for the combinations are for those 3 variables other than a report on occasion that "it doesn't work".

Doing anything with 8.5.9 is going way too far back. PySimpleGUI supports Python 3.4 and up, which is going back 6 years. That's been a challenge, but one that's reasonable as the Raspberry Pi often comes with this version of Python. There is little I can do to get around this other than forcing Pi users to update their Python version and I would rather not have that happen as it's not a trivial thing to do.

8.5.9 was released over 10 years ago. Some context... the same year 8.5.9 was released, so was 2.7.0. Python 3 was at 3.1. It's going back way too far to be of any real value. I understand the context you're using it for, which is to demonstrate that at one time no titlebar worked, but going back a decade to find a working version of anything is pretty extreme. It's a lifetime in software.

Hearing that MacOS v11 has any bearing on how tkinter operates is even more exasperating. The OS itself should have no impact... zero... on how tkinter and Python work.

It's disappointing to hear that the patch did not have a positive impact since what it does in set the wm_overrideredirect back to False, whichi is supposed to fix the problem. Here is the code that does is executed for no-titlebar on a Mac:

                MyFlexForm.TKroot.wm_overrideredirect(True)
                # Special case for Mac. Need to clear flag again if not tkinter version 8.6.10+
                if sys.platform.startswith('darwin') and ENABLE_MAC_NOTITLEBAR_PATCH and (sum([int(i) for i in tclversion_detailed.split('.')]) < 24):
                    print('* Applying Mac no_titlebar patch *')
                    MyFlexForm.TKroot.wm_overrideredirect(False)

The message "Application Mac no_titlebar patch" is shown just prior to setting the wm_overrideredirect back to False.

I would love to publish a version of PySimpleGUI that works with all of the Mac OS versions on all versions of tkinter, but that's what I've been attempting to do since the initial launch of PySimpleGUI, and it seems like the latest efforts have consistently fallen short.

The only known working fix I'm aware of at this point is requiring Mac users to install 8.6.10. That seems to produce results that work. The PySimpleGUI "fix" is shaping up to be an error message that is printed when someone attempts to create a no titlebar window or tries to set tooltips. It's a terrible solution from a useability standpoint, but I don't see any other way out of this. It beats requiring users to install a decade old version of tkinter.

I am concerned about the use of homebrew installs of Python and tkinter. It was only last year that we figured out that homebrew was the source of the problems and that installing from Python.org fixed those problems.

If you want to try adding additional calls to wm_overrideredirect or perform some other operation on the tkinter root object, you can access it directly using the Window member variable window.TKroot. Maybe you can find a combination of calls that will work. I'm striking out evidently.

I don't believe they're related, but you might want to try turning off the modal setting for the window as a test.

Just want to clear something up about tk/tcl 8.5.9... the only reason that I was using that version is because it was packaged with the homebrew python 3.9.1 installation. I was just using whatever they gave me. So like you said it may be a homebrew problem.

I'll mess around a bit with downloading some of the python.org releases. I have no problem helping you figure this out. Maybe I could do some testing that is bit more controlled for the different variables at play. It might take me a bit of time to do this, but If you have specific things that you want me to try other than what you mention previously, let me know.

Another thing that I wanted to mention is when I use tkinter and I make the call root.overrideredirect(True) a window won't even appear. So there is a bit more going on here if you ask me since when using PySimpleGUI the window will appear albeit it doesn't remove the titlebar, it only disables it. ( for versions < 8.6.10 )

I have no problem helping you figure this out.

Well.... I'm going to jump at this opportunity. I would like to solve this problem so that Mac users aren't forced to install 8.6.10. It's not an easy thing to do as has been shown through the above comments.

tk/tcl 8.5.9... the only reason that I was using that version is because it was packaged with the homebrew python 3.9.1 installation.

WOW.... jump plain WOW....

What a graphic example of why using Homebrew for Python installation is not a good idea. On one hand, I could see someone saying that because "it works" then it's fine to use, but it's not that simple. The amount of tkinter code added since 8.5.9 has to be significant as tkinter hasn't stood still for a decade.

I find this to be stunning news. :-( What an uphill battle.

Please try installing from Python.org. Some time back I added the need to install from Python.org to the documentation:

https://pysimplegui.readthedocs.io/en/latest/#macs

It's so strange that these problems seem to have come out of nowhere. Even though the number of Mac users is small, they do exist and they are using PySimpleGUI on tkinter. I'm sure that if this feature was broken 2 years ago that someone would have said something. They most certainly complained about the button color problems.

It would be nice if the testing were carefully organized and tracked. A matrix of combinations would be very helpful.

_I would like to see if there's a way to try older versions of everything and then step forward until something breaks._

That would be my ideal plan.

Just my 2 cents. I am not a Mac user, but I had to develop something in python for macOS, so this is were I got my limited experience from.

A couple of months ago, when I tried my options I tried python versions downloaded directly from python.org. At that time I spend a lot of time with python.org version 3.6.8, which comes bundled with Tcl/Tk 8.6.8. And it definitively has bugs when trying the various elements of PySimpleGUI. I think it is just tkinter, it is not so polished for macOS. By default Python's Homebrew version DOES NOT come with Tcl/Tk (see here and here), but of course there are probably many unofficial "brews". The Pyenv version does not come with Tcl/Tk. I used the trick I posted above to try Tcl/Tk 8.6.10. As I said, it is still not perfect, but in my testings it was definitively the better option. I had to make a product, I tested what worked and what not, and used the things that worked for my project.

BTW, modal windows don't work with python.org version 3.6.8, which comes bundled with Tcl/Tk 8.6.8 and they also give problems with a pyenv python and Tcl/Tk 8.6.10. See here.

edit: and macOS comes with Tcl/Tk 8.5.9 as part of the operating system. That is why you get that version if your python does not come bundled with a newer version Tcl/Tk. So, if your are using a regular brew install of python, that python will use the Tcl/Tk version that comes with the operating system. That is why you get Tcl/Tk 8.5.9 when using a regular homebrew python. And that is why my trick has to explicitly instruct pyenv's python to use the newer brew install of tcl-tk

Oh... I forgot about that modal thing.

The popup tests we've been running can be tried with modal disabled.

@tkozzer .... can you please try this popup test?

sg.popup_no_titlebar('This should not have a titlebar', modal=False)

Also, just to be sure the drag_anywhere isn't causing trouble, try this popup as well.

sg.popup_no_titlebar('This should not have a titlebar', modal=False, grab_anywhere=False)

To get the maximum control and visibility as to what options are being set, switching to making a Window is likely a better way to test. Here's a program that we can work with on this problem:

import PySimpleGUI as sg


layout = [[sg.Text('A no-titlebar test')],
          [sg.Button('Ok'), sg.Button('Exit')]]

window = sg.Window('Title', layout, no_titlebar=True, grab_anywhere=False, modal=False)

while True:
    event, values = window.read()
    print(event, values)
    if event in (sg.WIN_CLOSED, 'Exit'):
        break

window.close()

I'm putting together a release today as there are some changes that need to get up to PyPI quickly. If modal windows are indeed broken for the Mac, across the board, for all versions of tkinter, then I'll disable them in this release. Can someone verify that modal windows do not work correctly for 8.6.10 and other versions? I'm still not clear on the combinations of tkinter and MacOS that produce these different problems.

I can confirm that modal windows do not work for python.org python 3.6.8 that comes with Tcl/Tk 8.6.8. And they don't work for pyenv's python 3.6.11 working with Homebrew's Tcl/Tk 8.6.10. That are the only versions I tried with that particular problem.

pyenv doesn't supply any packages / libraries on its own. It helps with configuration. You still have to pick and choose what to install and then what you want to switch between.

For the Mac, the Python version doesn't matter so much as the tkinter and I think the MacOS version. tkinter 8.6.8 should run exactly the same on 3.6, 3.7, 3.8, 3.9. What can vary is which verrsion of tkinter gets installed when you install 3.6, 3.7, etc, at least on Windows. One reason to get Python from Python.org is that you do get a specific version of tkinter packaged with the install.

the Python version doesn't matter so much as the tkinter and I think the MacOS version

macOS High Sierra Version 10.13.6 for all my tests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scmanjarrez picture scmanjarrez  ·  5Comments

MikeTheWatchGuy picture MikeTheWatchGuy  ·  6Comments

thelou1s picture thelou1s  ·  4Comments

yogesh-aggarwal picture yogesh-aggarwal  ·  3Comments

xuguojun168 picture xuguojun168  ·  3Comments