How can I get the screen size in Tkinter? - python

I would like to know if it is possible to calculate the screen size using Tkinter.
I wanted this so that can make the program open up in the center of the screen...

import tkinter as tk
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

A possible solution
import os
os.system("xrandr | grep \* | cut -d' ' -f4")
My output:
1440x900
0

For Windows:
You can make the process aware of DPI to handle scaled displays.
import ctypes
try: # Windows 8.1 and later
ctypes.windll.shcore.SetProcessDpiAwareness(2)
except Exception as e:
pass
try: # Before Windows 8.1
ctypes.windll.user32.SetProcessDPIAware()
except: # Windows 8 or before
pass
Expanding on mouad's answer, this function is capable of handling multi-displays and returns the resolution of the current screen:
import tkinter
def get_display_size():
root = tkinter.Tk()
root.update_idletasks()
root.attributes('-fullscreen', True)
root.state('iconic')
height = root.winfo_screenheight()
width = root.winfo_screenwidth()
root.destroy()
return height, width

Related

Python centering window on "monitor" not "screen" or "desktop"

There are many questions on how to center a python tkinter window on the screen and the answer works well. My problem is my so-called "screen" looks like this:
Although you can move windows partially (or entirely) to the grey areas they won't actually show up on any of my three monitors. Top left monitor is 1920x1080, top right monitor is 3840x2160 and bottom right monitor is 1920x1080.
A program can be started via desktop icon which could be on any monitor or via gnome-terminal which could be on any monitor. How does one discover:
Which monitor was active when python was invoked?
Coordinates of active monitor within the screen real estate?
Although I'm using Gnome Desktop I'd like support for all Linux flavors using X11 or Wayland. Additionally I tried out ChromeOS Linux Beta lately and support for it would also be nice. Furthermore support for Windows and OSX is highly desired.
I've already installed and used many tools gi, wnck, xdotool, wmctrl that hem me into a corner. I'm hoping their is a popular python library (preferably installed via apt-get and not pip or pip3) that can expose "screen", "desktop" and "monitors" to python.
I answered my own question. It was one of those answers that stops you from falling asleep Saturday night at midnight so you get up at 1:00 am on Sunday and code until 4:30 am.
Here's the code which you can adapt for non-Ubuntu environments (using the "future code" functions):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#==============================================================================
#
# m - Wrapper for mserve.py
#
#==============================================================================
'''
Splash screen for mserve.
mserve has it's own list of required modules but this wrapper requires:
Gnome Desktop Toolkit (Gdk)
'''
from __future__ import print_function # Must be first import
try:
import tkinter as tk
PYTHON_VER="3"
except ImportError: # Python 2
import Tkinter as tk
PYTHON_VER="2"
import image as img # Routines for tk & photo images
import mserve # Script loaded as module for .pyc
# https://stackoverflow.com/a/36419702/6929343
import logging
logging.getLogger('PIL').setLevel(logging.WARNING)
import sys
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
level=logging.DEBUG,
stream=sys.stdout)
''' Future code '''
def get_active_window():
"""
From: https://stackoverflow.com/a/36419702/6929343
Get the currently active window.
Returns
-------
string :
Name of the currently active window.
"""
import sys
active_window_name = None
logging.info('sys.platform: ' + sys.platform)
print('sys.platform:', sys.platform)
if sys.platform in ['linux', 'linux2']:
# Alternatives: http://unix.stackexchange.com/q/38867/4784
try:
import wnck
except ImportError:
logging.info("wnck not installed")
wnck = None
if wnck is not None:
screen = wnck.screen_get_default()
screen.force_update()
window = screen.get_active_window()
if window is not None:
pid = window.get_pid()
with open("/proc/{pid}/cmdline".format(pid=pid)) as f:
active_window_name = f.read()
else:
try:
# Next 3 limes from: https://stackoverflow.com/a/43349245/6929343
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Wnck', '3.0')
# Continue with original code:
from gi.repository import Gtk, Wnck
gi = "Installed"
except ImportError:
logging.info("gi.repository not installed")
gi = None
if gi is not None:
Gtk.init([]) # necessary if not using a Gtk.main() loop
screen = Wnck.Screen.get_default()
screen.force_update() # recommended per Wnck documentation
active_window = screen.get_active_window()
pid = active_window.get_pid()
with open("/proc/{pid}/cmdline".format(pid=pid)) as f:
active_window_name = f.read()
elif sys.platform in ['Windows', 'win32', 'cygwin']:
# http://stackoverflow.com/a/608814/562769
import win32gui
window = win32gui.GetForegroundWindow()
active_window_name = win32gui.GetWindowText(window)
elif sys.platform in ['Mac', 'darwin', 'os2', 'os2emx']:
# http://stackoverflow.com/a/373310/562769
from AppKit import NSWorkspace
active_window_name = (NSWorkspace.sharedWorkspace()
.activeApplication()['NSApplicationName'])
else:
print("sys.platform={platform} is unknown. Please report."
.format(platform=sys.platform))
print(sys.version)
print("Active window: %s" % str(active_window_name))
return active_window_name
''' Future code '''
def get_GtkWindow(w):
# From: https://askubuntu.com/a/303754/307523
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gdk, Gtk
# Replace w with the GtkWindow of your application
w = Gtk.Window()
# Get the screen from the GtkWindow
s = w.get_screen()
# Using the screen of the Window, the monitor it's on can be identified
m = s.get_monitor_at_window(s.get_active_window())
# Then get the geometry of that monitor
monitor = s.get_monitor_geometry(m)
# This is an example output
print("Height: %s, Width: %s, X: %s, Y: %s" % \
(monitor.height, monitor.width, monitor.x, monitor.y))
''' Future code '''
def get_monitors():
"""
Get list of monitors in Gnome Desktop
"""
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
global NUMBER_OF_MONITORS, GNOME, ACTIVE_MONITOR, MONITOR_GEOMETRY
display = Gdk.Display.get_default()
screen = display.get_default_screen()
window = screen.get_active_window()
ACTIVE_MONITOR = screen.get_monitor_at_window(window)
print('ACTIVE_MONITOR:', ACTIVE_MONITOR)
# Gnome version 3.22 developed new monitor object
try:
# Gnome 3.22
NUMBER_OF_MONITORS = display.get_n_monitors()
monitor = display.get_monitor(ACTIVE_MONITOR)
MONITOR_GEOMETRY = monitor.get_geometry()
GNOME=3.22
except:
# Gnome 3.18
NUMBER_OF_MONITORS = screen.get_n_monitors()
MONITOR_GEOMETRY = screen.get_monitor_geometry(ACTIVE_MONITOR)
GNOME=3.18
# collect data about monitors
for index in range(NUMBER_OF_MONITORS):
if GNOME==3.22:
monitor = display.get_monitor(index)
geometry = monitor.get_geometry()
name = monitor.get_monitor_plug_name()
else:
geometry = screen.get_monitor_geometry(index)
name = screen.get_monitor_plug_name(index)
print("Monitor {} = {}x{}+{}+{}".format(index, geometry.width, \
geometry.height, geometry.x, geometry.y), name)
#get_monitors()
#print('ACTIVE_MONITOR:', ACTIVE_MONITOR, 'MONITOR_GEOMETRY:', MONITOR_GEOMETRY)
''' Start of REAL code used today (May 2, 2021) '''
def get_window_monitor(window):
"""
Returns the Gdk monitor geometry rectangle tkinter window is on.
If window is off screen force it into Monitor 1 (index 0).
:param window: Tkinter root or Topleel
"""
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
# global variables that might be useful down the road but not on May 2, 2021
global NUMBER_OF_MONITORS, GNOME
display = Gdk.Display.get_default()
screen = display.get_default_screen()
# Gnome version 3.22 deprecated what used to work 3.18.
# Gonme wasn't built in a day but, it was burned over night in next release!
try:
# Gnome 3.22
NUMBER_OF_MONITORS = display.get_n_monitors()
GNOME=3.22
except:
# Gnome 3.18
NUMBER_OF_MONITORS = screen.get_n_monitors()
GNOME=3.18
x = window.winfo_x() # Window's left coordinate on screen
y = window.winfo_y() # Window's top coordinate on screen
if x < 0: x = 0 # Window top left may be off screen!
if y < 0: y = 0
first_monitor = None
for index in range (NUMBER_OF_MONITORS):
if GNOME==3.22:
# Gnome version 3.22 developed new monitor object
monitor = display.get_monitor(index)
mon_geom = monitor.get_geometry()
else:
# Gnome version 3.18 uses screen object for monitor properties
mon_geom = screen.get_monitor_geometry(index)
# Save first monitor if needed later
if not first_monitor:
first_monitor = mon_geom
# Copmare to monitor's coordinates on screen and monitor width x height
if x < mon_geom.x: continue
if x >= mon_geom.x + mon_geom.width: continue
if y < mon_geom.y: continue
if y >= mon_geom.y + mon_geom.height: continue
# Window is comletely on this monitor.
return mon_geom
# If window off of screen use first monitor
return first_monitor
def center(window):
"""
From: https://stackoverflow.com/a/10018670/6929343
centers a tkinter window on monitor in multi-monitor setup
:param win: the main window or Toplevel window to center
"""
window.update_idletasks() # Refresh window's current position
mon_geom=get_window_monitor(window) # Monitor geometry window is on
if mon_geom is None:
logging.error("No monitors found!")
return None
# Calcuate X, Y of window to center within monitors X, Y, width and height
x = mon_geom.width // 2 - window.winfo_width() // 2 + mon_geom.x
y = mon_geom.height // 2 - window.winfo_height() // 2 + mon_geom.y
if x < 0: x = 0 # Window top left may be off screen!
if y < 0: y = 0
window.geometry('+{}+{}'.format(x, y))
window.deiconify() # Forces window to appear
return mon_geom
def main():
"""
Create splash screen and invoke mserve.py which takes a second or more
"""
splash = tk.Tk() # "very top" toplevel
splash.title("Music Server - mserve")
''' Set font style for all fonts including tkSimpleDialog.py '''
img.set_font_style() # Make messagebox text larger for HDPI monitors
''' Get splash image '''
splash_image = img.m_splash_image(300, 'white', 'lightskyblue', 'black')
# create and pack the canvas. Then load image file
canvas = tk.Canvas(width=300, height=300, bg='black')
canvas.pack(expand=tk.YES, fill=tk.BOTH)
canvas.create_image(0, 0, image=splash_image, anchor=tk.NW)
splash.update_idletasks() # This is required for visibility
# Cemter splash screen on monitor and get monitors geometry
mon_geom=center(splash)
splash.update() # This is required for visibility
# At this point make window undecorated, don't do it sooner!
# From: https://stackoverflow.com/a/37199655/6929343
splash.overrideredirect(True) # Undecorated to prevent close
# Call mserve module about 10k lines of code
mserve.main(toplevel=splash, mon_geom=mon_geom)
exit() # Required to close mserve library
splash.mainloop()
if __name__ == "__main__":
main()
# End of m

Why is a blank image in Tkinter 1/4 the size I specify?

I'm creating a canvas in a Python program using Tkinter and putting a solid single color image in it. (I need an image in there because later I'll be replacing that image with another, which is why I don't just specify the background.)
I specify the size of the canvas and have checked it when the window is open. It's 640x640. I specify the blank gray image to be the same size, but it comes up as 320x320, filling only a quarter of the canvas.
I know I can just change the image size to 1280x1280 so the whole canvas will be gray, but when I add other images to the canvas, I don't want to run into similar problems.
Here's the program:
#!/usr/bin/python
import datetime
import os
from PIL import Image, ImageTk
import sys
import Tkinter as tk
width = 640
height = 640
guiRoot = tk.Tk()
pWindow = tk.Frame(guiRoot)
BlankImage = None
CanvasMap = None
if __name__ == "__main__":
bmpfile = sys.argv[1]
print "Working with file: %s" % bmpfile
BlankImage = ImageTk.PhotoImage(Image.new('RGB', (width, height), 'gray'))
CanvasMap = tk.Canvas(guiRoot, width=width, height=height)
CanvasMap.create_image(0, 0, image=BlankImage)
CanvasMap.grid(row=0, column=0, columnspan=4) #later it's 4 columns
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
guiRoot.mainloop()
When it runs, it looks like this.
Why is the image only 1/4 size of the canvas? What do I need to do differently so when I use the same dimensions for the canvas and the image, they'll be the same size?
The entire image is displayed, but centered at canvas origin (0, 0), this is why you can only see the bottom right 1/4 of it.
You need either to off set the display to the center of the canvas (WIDTH // 2, HEIGHT // 2), or set the image handle to the top left corner.
Here is one approach:
import datetime
import os
from PIL import Image, ImageTk
import sys
import Tkinter as tk
width = 640
height = 640
guiRoot = tk.Tk()
pWindow = tk.Frame(guiRoot)
BlankImage = None
CanvasMap = None
if __name__ == "__main__":
bmpfile = sys.argv[1]
# print "Working with file: %s" % bmpfile
BlankImage = ImageTk.PhotoImage(Image.new('RGB', (width, height), 'gray'))
CanvasMap = tk.Canvas(guiRoot, width=width, height=height)
CanvasMap.create_image(width//2, height//2, image=BlankImage)
CanvasMap.grid(row=0, column=0, columnspan=4) #later it's 4 columns
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
guiRoot.mainloop()

Why tkinter scrollbar on tkinter frame(with canvas) of tkinter notebook tab, scroll only if mouse cursor over scroll slider?

This is the short note book code which scroll only when mouse cursor over the scroll slider.
Can't find any info about my problem. The examples which i found in internet etc work good sometimes , but in my case, not.
Python3.4 win7 64.
# -*- coding: utf-8 -*-
import tkinter
from tkinter import ttk
import sys,pickle,webbrowser
def cocoa_click(event):
webbrowser.open("http://stts.pythonanywhere.com/")
mainframe = tkinter.Tk()
mainframe_width = (mainframe.winfo_screenwidth() / 2 - 200)
mainframe_heigth = (mainframe.winfo_screenheight() / 2 - 250)
mainframe.geometry("%dx%d+%d+%d" % (1000, 600, mainframe_width, mainframe_heigth))
mainframe.title('DAS progress 132')
mainframe.resizable(False,True)
n_book = ttk.Notebook(mainframe)
n_book.pack(fill='both', expand='yes')
n_book.pressed_index = None
x_name=["tabnote1","tabnote2","tabnote3","tabnote4"]
x_container=[]; x_canvas=[]; x_scroll=[]; x_frame=[]
cvsw,cvsh=960,400;
sreg=(0,0,1000,1320)
for i in range(4):
x_container.append(tkinter.Frame(n_book))
x_container[i].pack(fill=tkinter.BOTH, expand=True)
n_book.add(x_container[i], text=x_name[i]) # add container to note book
x_canvas.append(tkinter.Canvas(x_container[i], width=cvsw, height=cvsh)) # add canvas to container
x_scroll.append(tkinter.Scrollbar(x_container[i], command=x_canvas[i].yview)) # add scroll to container
x_canvas[i].config(yscrollcommand=x_scroll[i].set, scrollregion=sreg)
x_canvas[i].pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)
x_scroll[i].config(width=240)
x_scroll[i].pack(side=tkinter.RIGHT, fill=tkinter.Y, expand=True)
cocoa = ttk.Button(mainframe,text="(: cocoa") # add button to mainframe - worked
cocoa.place(height=40,width=600,relx=0.4,rely=0)
cocoa.bind("<Button-1>",cocoa_click)
mainframe.mainloop()
i found the dirty solution for my case but it not crossplatform(linux have difference behavior)
# -*- coding: utf-8 -*-
import tkinter
from tkinter import ttk
import sys,pickle,webbrowser
def on_mousewheel(event):
try:
print("e ",event)
shift = (event.state & 0x1) != 0
canvas=event.widget
scroll = -1 if event.delta > 0 else 1
if shift:
canvas.xview_scroll(scroll, "units")
else:
canvas.yview_scroll(scroll, "units")
except:pass
def cocoa_click(event):
webbrowser.open("http://stts.pythonanywhere.com/")
mainframe = tkinter.Tk()
mainframe_width = (mainframe.winfo_screenwidth() / 2 - 200)
mainframe_heigth = (mainframe.winfo_screenheight() / 2 - 250)
mainframe.geometry("%dx%d+%d+%d" % (1000, 600, mainframe_width, mainframe_heigth))
mainframe.title('DAS progress 132')
mainframe.resizable(False,True)
n_book = ttk.Notebook(mainframe)
n_book.pack(fill='both', expand='yes')
n_book.pressed_index = None
x_name=["tabnote1","tabnote2","tabnote3","tabnote4"]
x_container=[]; x_canvas=[]; x_scroll=[]; x_frame=[]
cvsw,cvsh=960,400;
sreg=(0,0,1000,1320)
for i in range(4):
x_container.append(tkinter.Frame(n_book))
x_container[i].pack(fill=tkinter.BOTH, expand=True)
n_book.add(x_container[i], text=x_name[i]) # add container to note book
x_canvas.append(tkinter.Canvas(x_container[i], width=cvsw, height=cvsh)) # add canvas to container
x_scroll.append(tkinter.Scrollbar(x_container[i], command=x_canvas[i].yview)) # add scroll to container
x_canvas[i].config(yscrollcommand=x_scroll[i].set, scrollregion=sreg)
x_canvas[i].pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)
x_scroll[i].config(width=240)
x_scroll[i].pack(side=tkinter.RIGHT, fill=tkinter.Y, expand=True)
x_canvas[i].bind_all("<MouseWheel>", on_mousewheel) # index always 3
cocoa = ttk.Button(mainframe,text="(: cocoa") # add button to mainframe - worked
cocoa.place(height=40,width=600,relx=0.4,rely=0)
cocoa.bind("<Button-1>",cocoa_click)
mainframe.mainloop()

Toplevel inside another Toplevel in tkinter [duplicate]

I'm not very good with tkinter of python, but i would like to know if theres a way to make a window inside a window, where that window cannot get out of the main window's bounds.
Heres my current code:
from tkinter import *
root = Tk()
root.title("Main Window")
root.geometry("640x480+100+100")
sub = Toplevel(root)
sub.title("Sub Window")
sub.geometry("320x240+125+125")
mainloop()
it would look like this:
I would like to know how I can isolate the Sub Window to keep it inside the main window even if i drag it out.
Thank you very much.
There is no built in method of doing so. However I've made a work around to accommodate it. Keep in mind that when trying to move the sub window outside the main window it isn't a smooth lock so it does get jumpy. Another issue is that because of the configure events I can't get the sub window position relative to main window to maintain it while moving the main window. Still working around that. However the code below does work and should be of use to you.
import tkinter as tk
root = tk.Tk()
root.title("Main Window")
root.geometry("640x480")
sub = tk.Toplevel(root)
sub.transient(root) #Keeps sub window on top of root
sub.title('Sub Window')
sub.minsize(320, 240)
sub.maxsize(320, 240)
pos = []
def main_move(event):
#When the main window moves, adjust the sub window to move with it
if pos:
sub.geometry("+{0}+{1}".format(pos[0], pos[1]))
# Change pos[0] and pos[1] to defined values (eg 50) for fixed position from main
def sub_move(event):
# Set the min values
min_w = root.winfo_rootx()
min_h = root.winfo_rooty()
# Set the max values minus the buffer for window border
max_w = root.winfo_rootx() + root.winfo_width() - 15
max_h = root.winfo_rooty() + root.winfo_height() - 35
# Conditional statements to keep sub window inside main
if event.x < min_w:
sub.geometry("+{0}+{1}".format(min_w, event.y))
elif event.y < min_h:
sub.geometry("+{0}+{1}".format(event.x, min_h))
elif event.x + event.width > max_w:
sub.geometry("+{0}+{1}".format(max_w - event.width, event.y))
elif event.y + event.height > max_h:
sub.geometry("+{0}+{1}".format(event.x, max_h - event.height))
global pos
# Set the current sub window position
pos = [event.x, event.y]
root.bind('<Configure>', main_move)
sub.bind('<Configure>', sub_move)
root.mainloop()
There's nothing built-in to facilitate this, though there are enough building blocks to build your own. You can, for example, create a frame with some custom bindings that allow you to move it around its parent using the place geometry manager.

How to make a window fullscreen in a secondary display with tkinter?

I know how to make a window fullscreen in the "main" display, but even when moving my app's window to a secondary display connected to my PC, when I call:
self.master.attributes('-fullscreen', True)
to fullscreen that window, it does so in the "main" display and not in the secondary one (the app's window disappears from the secondary display and instantly appears in the "main" one, in fullscreen).
How can I make it fullscreen in the secondary display?
This works on Windows 7: If the second screen width and height are the same as the first one, you can use win1 or win2 geometry of the following code depending its relative position(leftof or rightof) to have a fullscreen in a secondary display:
from Tkinter import *
def create_win():
def close(): win1.destroy();win2.destroy()
win1 = Toplevel()
win1.geometry('%dx%d%+d+%d'%(sw,sh,-sw,0))
Button(win1,text="Exit1",command=close).pack()
win2 = Toplevel()
win2.geometry('%dx%d%+d+%d'%(sw,sh,sw,0))
Button(win2,text="Exit2",command=close).pack()
root=Tk()
sw,sh = root.winfo_screenwidth(),root.winfo_screenheight()
print "screen1:",sw,sh
w,h = 800,600
a,b = (sw-w)/2,(sh-h)/2
Button(root,text="Exit",command=lambda r=root:r.destroy()).pack()
Button(root,text="Create win2",command=create_win).pack()
root.geometry('%sx%s+%s+%s'%(w,h,a,b))
root.mainloop()
Try:
from Tkinter import *
rot = Tk()
wth,hgh = rot.winfo_screenwidth(),rot.winfo_screenheight()
#take desktop width and hight (pixel)
_w,_h = 800,600 #root width and hight
a,b = (wth-_w)/2,(hgh-_h)/2 #Put root to center of display(Margin_left,Margin_top)
def spann():
def _exit():
da.destroy()
da = Toplevel()
da.geometry('%dx%d+%d+%d' % (wth, hgh,0, 0))
Button(da,text="Exit",command=_exit).pack()
da.overrideredirect(1)
da.focus_set()#Restricted access main menu
Button(rot,text="Exit",command=lambda rot=rot : rot.destroy()).pack()
but = Button(rot,text="Show SUB",command=spann)
but.pack()
rot.geometry('%sx%s+%s+%s'%(_w,_h,a,b))
rot.mainloop()
""" Geometry pattern 'WxH+a+b'
W = Width
H = Height
a = Margin_left+Margin_Top"""
Super simple method working in 2021
This works even if both displays are different resolutions. Use geometry to offset the second display by the width of the first display. The format of the geometry string is <width>x<height>+xoffset+yoffset:
root = tkinter.Tk()
# specify resolutions of both windows
w0, h0 = 3840, 2160
w1, h1 = 1920, 1080
# set up a window for first display, if wanted
win0 = tkinter.Toplevel()
win0.geometry(f"{w0}x{h0}+0+0")
# set up window for second display with fullscreen
win1 = tkinter.Toplevel()
win1.geometry(f"{w1}x{h1}+{w0}+0") # <- this is the key, offset to the right by w0
win1.attributes("-fullscreen", True)
As long as you know the width of the first display, this will work fine. The X system TK runs on puts the second monitor to the right of the first one by default.
Windows, Python 3.8
In this solution, pressing F11 will make the window fullscreen on the current screen.
Note that self.root.state("zoomed") is Windows specific according to doc.
self.root.overrideredirect(True) is weird in Windows and may have unwanted side effects. For instance I've had issues related to changing screen configuration with this option active.
#!/usr/bin/env python3
import tkinter as tk
class Gui:
fullScreen = False
def __init__(self):
self.root = tk.Tk()
self.root.bind("<F11>", self.toggleFullScreen)
self.root.bind("<Alt-Return>", self.toggleFullScreen)
self.root.bind("<Control-w>", self.quit)
self.root.mainloop()
def toggleFullScreen(self, event):
if self.fullScreen:
self.deactivateFullscreen()
else:
self.activateFullscreen()
def activateFullscreen(self):
self.fullScreen = True
# Store geometry for reset
self.geometry = self.root.geometry()
# Hides borders and make truly fullscreen
self.root.overrideredirect(True)
# Maximize window (Windows only). Optionally set screen geometry if you have it
self.root.state("zoomed")
def deactivateFullscreen(self):
self.fullScreen = False
self.root.state("normal")
self.root.geometry(self.geometry)
self.root.overrideredirect(False)
def quit(self, event=None):
print("quiting...", event)
self.root.quit()
if __name__ == '__main__':
Gui()

Categories