Why not import PyQt5 modules, such as QPainter, QColor, QFont from PyQt5.QtGui?

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPainter, QColor, QFont
from PyQt5.QtCore import Qt
import sys

When you import QPainter, QColor, QFont. Qt (2-3 line of code) I get this error: No name "QPainter" in module "PyQt5.QtGui".
With other modules the same error.
April 4th 20 at 00:32
1 answer
April 4th 20 at 00:34
Make sure that you have no Cyrillic characters in the user name, computer, etc. Reinstall PyQt5. I've just checked:

1) Created a virtual environment (Python 3.8.1, 64-bit Windows)
2) Set up PIP om PyQt5 (5.14.0)
3) Took a sample from the page zetcode.com/gui/pyqt5/painting example
drawingtext.py ...

#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
ZetCode PyQt5 tutorial

In this example, we draw text in Russian Cylliric.

Author: Jan Bodnar
Website: zetcode.com
Last edited: August 2017
"""

import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QColor, QFont
from PyQt5.QtCore import Qt


class Example(QWidget):

 def __init__(self):
super().__init__()

self.initUI()

 def initUI(self):

 self.text = "Leo Tolstoy\Panna Karenina"

 self.setGeometry(300, 300, 280, 170)
 self.setWindowTitle('Drawing text')
self.show()

 def paintEvent(self, event):

 qp = QPainter()
qp.begin(self)
 self.drawText(event, qp)
qp.end()

 def drawText(self, event, qp):

 qp.setPen(QColor(168, 34, 3))
 qp.setFont(QFont('Decorative', 10))
 qp.drawText(event.rect(), Qt.AlignCenter, self.text)


if __name__ == '__main__':

 app = QApplication(sys.argv)
 ex = Example()
 sys.exit(app.exec_())


4) Launched (from Pycharm)

Everything works.

Find more questions by tags Python