Найти - Пользователи
Полная версия: проблемы с пониманием
Начало » Python для новичков » проблемы с пониманием
1
dezzel
Мне необходимо, чтобы при нажатии на кнопку “Teacher” вызывался второй виджет, однако, мне выдаёт ошибку “NameError: name ‘qx’ is not defined” использую Python 3.5 и PyQt5
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QInputDialog, QApplication, QLabel, QGridLayout )


class start_window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.qx = teacher()
self.qx.initlol(self)

def initUI(self):
lbl1 = QLabel('If you need to add some questions, create surveys and view results \nof your pupils, please click "Teacher" button.', self)
lbl1.move(20, 10)

lbl2 = QLabel('If you need to pass the survey, please click "Pupil" button.', self)
lbl2.move(400, 10)
self.btn1 = QPushButton('Teacher', self)
self.btn1.move(150, 50)
self.btn1.clicked.connect(qx.initlol())

self.btn2 = QPushButton('Pupil', self)
self.btn2.move(500, 50)
self.btn2.clicked.connect(self.showDialog2)

self.setGeometry(300, 300, 700, 100)
self.setWindowTitle('Start')
self.show()

def showDialog2(self):
text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your ID:')

if ok:
self.le.setText(str(text))

class teacher(QWidget):
def __init__(self):
super().__init__()
self.initlol()

def initlol(self):

Login = QLabel('Login:')
Password = QLabel('Password:')

LoginEdit = QLineEdit()
PasswordEdit = QLineEdit()

grid = QGridLayout()
grid.setSpacing(5)

grid.addWidget(Login, 1, 0)
grid.addWidget(LoginEdit, 1, 1)

grid.addWidget(Password, 2, 0)
grid.addWidget(PasswordEdit, 2, 1)

self.setLayout(grid)

self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Access')
self.show()

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = start_window()
sys.exit(app.exec_())
Firik
Может
self.btn1.clicked.connect(self.qx.initlol())
?
dezzel
Firik
Может
нет, не получалось
я попробовал так, но теперь TypeError: argument 1 has unexpected type ‘NoneType’ в 22 строке:
class start_window(QWidget):
def __init__(self):
super().__init__()
self.initUI()



def initUI(self):
self.qx = Teacher()
qx = self.qx
lbl1 = QLabel('If you need to add some questions, create surveys and view results \nof your pupils, please click "Teacher" button.', self)
lbl1.move(20, 10)

lbl2 = QLabel('If you need to pass the survey, please click "Pupil" button.', self)
lbl2.move(400, 10)
self.btn1 = QPushButton('Teacher', self)
self.btn1.move(150, 50)
self.btn1.clicked.connect(qx.initUI())

self.btn2 = QPushButton('Pupil', self)
self.btn2.move(500, 50)
self.btn2.clicked.connect(self.showDialog2)

self.setGeometry(300, 300, 700, 100)
self.setWindowTitle('Start')
self.show()

def showDialog2(self):
text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your ID:')

if ok:
self.le.setText(str(text))

class Teacher(QWidget):
def __init__(self):
super().__init__()
self.initUI()

def initUI(self):

Login = QLabel('Login:')
Password = QLabel('Password:')

LoginEdit = QLineEdit()
PasswordEdit = QLineEdit()

grid = QGridLayout()
grid.setSpacing(5)

grid.addWidget(Login, 1, 0)
grid.addWidget(LoginEdit, 1, 1)

grid.addWidget(Password, 2, 0)
grid.addWidget(PasswordEdit, 2, 1)

self.setLayout(grid)

self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Access')
self.show()

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = start_window()
sys.exit(app.exec_())
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB