2
You have to use a library that has the design features - and that intermediates with the operating system.
To "black the screen" and you can draw everything from scratch, one of the easiest to use in Python is the pygame. (To install pygame, in general you only need to type pip install pygame
command line (cmd in windows)
To draw in the "root" window of the operating system, where the background and icons are located, it is possible - but not usual - using libraries like Qt, or the direct API of the operating system (Xlib on Linux) - and even if the system authorizes you, what you draw is subject to being suddenly erased in any redesign of the screen.
With pygame, to draw on the full screen, just call the window setup by passing the indicator pygame.FULLSCREEN
as second parameter. It is important to remember to call pygame.quit()
in a building of the type try ...finally
, otherwise, if your program gives some error while it is full screen, you may get "stuck" on the graphical screen.
Minimum example to erase the screen, fill it with white color, draw a red rectangle, wait a few seconds and finish:
import time
import pygame
def main():
try:
screen = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN)
screen.fill((255,255,255))
pygame.draw.rect(screen, (255,0,0), (50,50,300,200))
pygame.display.flip()
time.sleep(5)
finally:
pygame.quit()
main()
Note that I use the resolution "1024,768" - which is kind of "universal" - you can make the pygame print (even print) out of pygame.display.list_modes()
to know the native resolutions available on your machine.
In addition, pygame’s own documentation on https://www.pygame.org/docs/ref/draw.html and on the "Events" page can help you create more elaborate drawings and interact with the keyboard and mouse.
You have to make specific calls in the graphical Apis of each operating system.
– Augusto Vasques