Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current Screen Size in Python3 with PyQt5

Is there an alternative in Qt5 python3 to the following code :

https://askubuntu.com/questions/153549/how-to-detect-a-computers-physical-screen-size-in-gtk

from gi.repository import Gdk
s = Gdk.Screen.get_default()
print(s.get_width(), s.get_height())
like image 785
AlbanMar31 Avatar asked Mar 09 '16 09:03

AlbanMar31


People also ask

Which is better PyQt5 or PySide2?

PyQt is significantly older than PySide and, partially due to that, has a larger community and is usually ahead when it comes to adopting new developments. It is mainly developed by Riverbank Computing Limited and distributed under GPL v3 and a commercial license.

What is the latest version of PyQt5?

The latest iteration of PyQt is v5. 11.3. It fully supports Qt 5.11.

Why PyQt5 is used in Python?

There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library.


Video Answer


2 Answers

You can get the primary screen from the QApplication, which returns a QScreen object giving access to many useful properties:

import sys
from PyQt5 import QtWidgets

app = QtWidgets.QApplication(sys.argv)

screen = app.primaryScreen()
print('Screen: %s' % screen.name())
size = screen.size()
print('Size: %d x %d' % (size.width(), size.height()))
rect = screen.availableGeometry()
print('Available: %d x %d' % (rect.width(), rect.height()))

Note that the primaryScreen method is static, so if you've already created an instance of QApplication elsewhere in your application, can easily get a QScreen object later on like this:

screen = QApplication.primaryScreen()
like image 148
ekhumoro Avatar answered Oct 24 '22 12:10

ekhumoro


from PyQt5.QtWidgets import QApplication, QWidget
self.desktop = QApplication.desktop()
self.screenRect = self.desktop.screenGeometry()
self.height = self.screenRect.height()
self.width = self.screenRect.width()

You can see here - https://www.programmersought.com/article/58831562998/

like image 23
Megastar Avatar answered Oct 24 '22 14:10

Megastar