'Ubuntu pyautogui .screenshot() returns blackscreen image

Im trying to verify the location of some icons on the screen using .screenshot() function of pyautogui due to it always return None when using .locateOnScreen(). Upon checking the generated .png file it is only a black screen.

Here is my setup:

  • OS: Ubuntu 21.10
  • Python 3.9.7
  • Pyautogui 0.9.53
  • Pillow 9.1.0

Code:

   def automate_export():
       screen_width, screen_height = pyautogui.size()
       screen = pyautogui.screenshot("Screenshoooot.png", region=(0, 0, screen_width, screen_height))

Proof of black screen generated by program



Solution 1:[1]

i had the same problem and i fixed it with the help of this article: https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop

note:if you can't find WaylandEnable=true in the file write:WaylandEnable=false then restart

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nxte