Display Fullscreen Mode on Tkinter

Display fullscreen mode on Tkinter

This creates a fullscreen window. Pressing Escape resizes the window to '200x200+0+0' by default. If you move or resize the window, Escape toggles between the current geometry and the previous geometry.

import Tkinter as tk

class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
master.bind('<Escape>',self.toggle_geom)
def toggle_geom(self,event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom

root=tk.Tk()
app=FullScreenApp(root)
root.mainloop()

How do I display a tkinter application in fullscreen on macOS?

I believe what you want to do is use

root.wm_attributes('-fullscreen','true')

Try this instead. It should do the trick.

from tkinter import *
root = Tk()

root.wm_attributes('-fullscreen','true')

def quitApp():
root.destroy()

button = Button(text = 'QUIT', command = quitApp).pack()

root.mainloop()

If this does not work because of the MacOS then take a look at this link This useful page has sever examples of how to manage mack windows in tkinter. And I believe what you may need to get borderless fullscreen.

This bit of code might be what you need:

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

Note: If you do use this option then you will need to remove root.wm_attributes('-fullscreen','true') from your code or just comment it out.

Update:

There is also another bit of code for tkinter 8.5+.

If you are using python with tkinter 8.5 or newer:

root.wm_attributes('-fullscreen', 1)

How can I set default screen tkinter not full screen?

root.geometry("500x100") #Width x Height

Use this code to change your Tkinter screen size. Here root is the main window, geometry() is the function used to change screen size. 500 is the width and 100 is the height

Tkinter full screen

Try win.state('zoomed'), where win is your Tk window instance.

Edit :

Try something like this. Simply treat this class like a Tk window class.

class Void (tk.Tk) :
def __init__ (self, color='black') :
tk.Tk.__init__(self)
self.wm_state('zoomed')
self.config(bg=color)
self.overrideredirect(True)
self.attributes('-topmost', True)


Related Topics



Leave a reply



Submit