I would appreciate any help with the issue I am facing.
When I do execute my program it does give me the error message:
AttributeError: 'QLineEdit' object has no attribute 'setTabEnabled'
the program is as followiong:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTabWidget, QWidget, QVBoxLayout, QLineEdit, QPushButton
import os
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Four tabs test1")
self.setGeometry(100, 100, 600, 400)
tabs = QTabWidget()
tab1 = QWidget()
tab2 = QWidget()
tab3 = QWidget()
tab4 = QWidget()
tabs.addTab(tab1, "PAG1")
tabs.addTab(tab2, "PAG2")
tabs.addTab(tab3, "PAG3")
tabs.addTab(tab4, "PAG4")
tabs.setTabEnabled(0, False)
tabs.setTabEnabled(1, False)
tabs.setTabEnabled(2, False)
tabs.setTabEnabled(3, True)
#Creazione del textbox e pulsante in Tab4
layout4 = QVBoxLayout()
pswtextbox = QLineEdit()
pswtextbox.setPlaceholderText("ENTER PSW")
psw_button = QPushButton("SUBMIT")
layout4.addWidget(pswtextbox)
layout4.addWidget(psw_button)
tab4.setLayout(layout4)
psw_button.clicked.connect(self.check_password)
self.setCentralWidget(tabs)
def check_password(self):
pswtextbox = self.centralWidget().currentWidget().findChild(QLineEdit)
password = pswtextbox.text()
with open("PSW.txt", "r") as file:
stored_password = file.read().strip()
if password == stored_password:
self.unlock_tabs()
else:
print("Wrong Password")
def unlock_tabs(self):
tabs = self.centralWidget().currentWidget().findChild(QLineEdit)
tabs.setTabEnabled(0, True)
tabs.setTabEnabled(1, True)
tabs.setTabEnabled(2, True)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
the main idea of this program is to have some tabs locked and to have the same unlocked upon inputting the right password.
Everything seems working fine up to def check_password(self)
part where I get the error as described before
Nico is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.