0

I am using pygame to make a game on a Mac. I am trying to get my window to fill the screen without going fullscreen. The problem is that the height of Dock at the bottom and the Topbar are not subtracted when I used pygame.display.get_surface().get_size() (which returned 1366x 768). I know that Dock size varies from MacBook to MacBook because people change it and I am trying to make my game work seamlessly on all of classmates' MacBooks as well as their Windows computers.

I want to get screen size excluding the Dock/Topbar on Mac and the Taskbar on windows. I've seen a thread on how to do it in Java linked here, but I cannot seem to find anything about it for Python.

trumpetlicks
  • 7,033
  • 2
  • 19
  • 33

2 Answers2

0

Well assuming you are using tkinter, the simple solution would be to implement:

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()

to show the toolbar while filling screen:

import tkinter as tk

class Fullscreen_Example:
    def __init__(self):
        self.window = tk.Tk()
        self.fullScreenState = False
        self.window.attributes("-fullscreen", self.fullScreenState)

        self.w, self.h = self.window.winfo_screenwidth(), self.window.winfo_screenheight()
        self.window.geometry("%dx%d" % (self.w, self.h))

        self.window.bind("<F11>", self.toggleFullScreen)
        self.window.bind("<Escape>", self.quitFullScreen)

        self.window.mainloop()

    def toggleFullScreen(self, event):
        self.fullScreenState = not self.fullScreenState
        self.window.attributes("-fullscreen", self.fullScreenState)

    def quitFullScreen(self, event):
        self.fullScreenState = False
        self.window.attributes("-fullscreen", self.fullScreenState)

if __name__ == '__main__':
    app = Fullscreen_Example()
Suarez
  • 93
  • 1
  • 1
  • 4
  • I am using pygame, and I'm just trying to get the dimensions of the available area so I can set the size of my pygame window to the available area. – Ben Morrison Apr 28 '20 at 21:21
  • Good! to use pygame and tkinter just type "import tkinter as tk" or just "import tkinter" and you can use the code I have provided, check my other answer for my clarification if needed. :D – Suarez Apr 28 '20 at 21:27
  • I am still confused how I'd use your tkinter for pygame. I've never used tkinter before, just pygame. – Ben Morrison Apr 28 '20 at 23:16
  • I understand that I have to type import tkinter, but pygame uses its own windows which I believe are based off of tkinter, and I don't know how I can still use the pygame windows if I am making a new window in tkinter. – Ben Morrison Apr 29 '20 at 17:23
0

Great! just copy the code I have provided and that should do! If you're trying to retreive the variables that represent the screen size, simply :

from win32api import GetSystemMetrics

print("Width =", GetSystemMetrics(0))
print("Height =", GetSystemMetrics(1))
Suarez
  • 93
  • 1
  • 1
  • 4