'pyqt.returnPressed conecting to function 2 times,need 1
I saw this method of pass information from Main to other windows, and everything works fine on another part of the application.
class uch_info(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(uch_info, self).__init__(parent)
self.ui = Ui_Uch_info()
self.ui.setupUi(self)
def displayInfo(self):
self.show()
class main_window(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(main_window, self).__init__(parent)
self.uch_info= uch_info()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.tableWidget_uch.cellDoubleClicked.connect(self.open_uch_Window)
def open_uch_Window(self):
row = self.ui.tableWidget_uch.currentIndex().row()
users = db.reference('users').get()
users_list=users.get(list(users.keys())[row])
self.uch_info.ui.lineEdit.returnPressed.connect(partial(self.button, users_list.get('login')))
self.uch_info.displayInfo()
def button(self,login):
print('button clicked,login',login)
Here, when you first click on tableWidget_uch everything is fine, and the open_uch_Window window opens and when the returnPressed event is called, it displays only 1 time 1 login.
output
button clicked,login dimarom4
but when i click on tableWidget_uch and open the open_uch_Window window second times, and call the returnPressed event, it returns two times 'print('button clicked,login',login)': first from past call with login1 and second from this call with login2
output button clicked,login dimarom4 button clicked,login zayaz
how to make it correct? so that each returnPressed.connect connects only once to the button
Solution 1:[1]
I use self.uch_info.ui.lineEdit.returnPressed.disconect() after print in button
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dima romanika |
