Tkinter full screen not working in Python 3.10 for Mac OS

Viewed 62

I just upgraded Python from 3.8 to 3.10 and the Tkinter full screen attribute no longer works as it used to.

I'm using Mac OS Big Sur 11.6.6 (Macbook M1). I had Python 3.8 installed on this Macbook and it has been working fine until I upgraded Python today.

Here is the code and the root window does not show in full screen for Python 3.10:

if __name__ == '__main__':

root = tkinter.Tk()

root.attributes('-fullscreen', True)

root.mainloop()

Any help would be much appreciated because I'm stuck. I have also seen other problems with my UI in Python 3.10 so if I'm not able to solve these problems I may revert back to Python 3.8 :(

UPDATE 1 I've noticed that my Macbook makes a bleep sound when I run with the full screen attribute but it does not if I comment out that row.

I've also noticed that it makes the same bleep sound when I type on the keyboard e.g. in an Entry widget. It did not use to do that in Python 3.8, so may be related.

UPDATE 2 I am able to do a somewhat ugly workaround by using a delay and setting the full screen attribute after 250 ms with a root.after(...) function. Then it works. It does not look very nice since empty white backgrounds flash by before the actual program opens.

1 Answers

You need to use root.wm_attributes() instead.

Example

import tkinter as tk

root = tk.Tk()
root.wm_attributes('-fullscreen','true')
root.mainloop()

Yet another way to do this is by calling tcl as follows

root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")

use only either of the methods.

Related