While working with PyQt6 as a beginner, I came across an error stating that my class did not possess an attribute, causing me great confusion.
import sys
from BckendPrcss import gen_psswrd
from PyQt6.QtWidgets import QWidget, QApplication, QLineEdit, QPushButton, QVBoxLayout, QTextEdit, QPlainTextEdit
from PyQt6.QtGui import QIcon
class GuiApp(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Password Generator')
self.setMinimumSize(600, 500)
self.setBaseSize(600, 500)
self.button = QPushButton('Press this button to generate the password.', clicked=self.get_psswrd())
self.txtbox = QTextEdit()
self.txtbox.setFixedSize(200, 90)
layout = QVBoxLayout
self.setLayout(layout)
layout.addWidget(self.txtbox)
layout.addWidget(self.button)
def get_psswrd(self):
if self.txtbox:
pass
var= gen_psswrd()
self.txtbox.setText('This is your password:{} '.format(var))
app = QApplication(sys.argv)
window = GuiApp()
window.show()
sys.exit(app.exec())
After researching for a while, I couldn’t find anything to explain why it was happening. This is the error I received.
AttributeError: 'GuiApp' object has no attribute 'txtbox'
I tried to re-indent the blocks of code to fix any potential issues arising from improper indentation. It still didn’t fix anything, and I’ve confirmed that my tab key indents with four spaces.
Chimdiebube Okonkwo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.