patternpythonMinor
PyQt5 GUI Application
Viewed 0 times
pyqt5guiapplication
Problem
I'd just like this PyQt5 code reviewed. I'm relatively new to classes and GUI programming, and wanted to make sure I wasn't doing anything too bad. If absolutely necessary, I can give you the other stuff I've created that this program uses.
```
import sys
from PyQt5 import QtCore, QtWidgets, QtGui, QtMultimedia
from irish_dictionary import irish_dictionary
from audio_grabber import entry_search, related_matches
# Create the widgets used by both versions
class Text(QtWidgets.QWidget):
""" This class creates the text widget"""
def __init__(self, parent=None):
super().__init__(parent)
self.text_entry = QtWidgets.QTextEdit(parent)
self.text_entry.setReadOnly(True)
# Create Irish version widgets
class IrishLabel(QtWidgets.QWidget):
def __init__(self, parent=None):
""" This class creates the Irish language label, entry box, and version switcher """
super().__init__(parent)
self.irish_label = QtWidgets.QLabel("Cuir d'fhocal anseo:")
self.irish_entry = QtWidgets.QLineEdit()
self.english_language_button = QtWidgets.QPushButton("English Version")
self.english_language_button.clicked.connect(lambda: self.irish_to_english())
@staticmethod
def irish_to_english():
""" This method converts the Irish language version to English """
irish_version.hide()
english_version.show()
irish_version.layout().removeWidget(irish_version.text_entry)
english_version.layout().addWidget(english_version.text_entry, 3, 0, 24, 8)
english_version.resize(200, 400)
english_version.center()
class IrishButtons(IrishLabel):
""" this class creates the Irish language buttons"""
def __init__(self, parent=None):
super().__init__(parent)
# Set buttons and enabled status
self.bearla_button = QtWidgets.QPushButton("Béarla")
self.gaeilge_button = QtWidgets.QPushButton("Gaeilge")
self.connacht_button = QtWidgets.QPus
```
import sys
from PyQt5 import QtCore, QtWidgets, QtGui, QtMultimedia
from irish_dictionary import irish_dictionary
from audio_grabber import entry_search, related_matches
# Create the widgets used by both versions
class Text(QtWidgets.QWidget):
""" This class creates the text widget"""
def __init__(self, parent=None):
super().__init__(parent)
self.text_entry = QtWidgets.QTextEdit(parent)
self.text_entry.setReadOnly(True)
# Create Irish version widgets
class IrishLabel(QtWidgets.QWidget):
def __init__(self, parent=None):
""" This class creates the Irish language label, entry box, and version switcher """
super().__init__(parent)
self.irish_label = QtWidgets.QLabel("Cuir d'fhocal anseo:")
self.irish_entry = QtWidgets.QLineEdit()
self.english_language_button = QtWidgets.QPushButton("English Version")
self.english_language_button.clicked.connect(lambda: self.irish_to_english())
@staticmethod
def irish_to_english():
""" This method converts the Irish language version to English """
irish_version.hide()
english_version.show()
irish_version.layout().removeWidget(irish_version.text_entry)
english_version.layout().addWidget(english_version.text_entry, 3, 0, 24, 8)
english_version.resize(200, 400)
english_version.center()
class IrishButtons(IrishLabel):
""" this class creates the Irish language buttons"""
def __init__(self, parent=None):
super().__init__(parent)
# Set buttons and enabled status
self.bearla_button = QtWidgets.QPushButton("Béarla")
self.gaeilge_button = QtWidgets.QPushButton("Gaeilge")
self.connacht_button = QtWidgets.QPus
Solution
Why do some of your classes have an inline comment,
There is no need for the inline comment,
Your docstrings are also slightly lacking as well. Some useful information that your could include in your docstrings can be seen below:
#, and then a docstring describing the exact same thing? Here's an example of that:# Create English version widgets
class EnglishLabel(QtWidgets.QWidget):
""" This class Creates English labels"""
...There is no need for the inline comment,
#, it should be removed. On the note of comments as well, docstrings are generally written like this, with newlines:"""
...
"""Your docstrings are also slightly lacking as well. Some useful information that your could include in your docstrings can be seen below:
- A slightly more detailed description of what the class/function does.
- An (optional) description of how the class/function does it's task.
- A description of the class/function's arguments.
Code Snippets
# Create English version widgets
class EnglishLabel(QtWidgets.QWidget):
""" This class Creates English labels"""
..."""
...
"""Context
StackExchange Code Review Q#75648, answer score: 2
Revisions (0)
No revisions yet.