简体   繁体   English

pyqt.return按下连接function 2次,需要1次

[英]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.我看到了这种将信息从 Main 传递到其他 windows 的方法,并且在应用程序的另一部分一切正常。

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.在这里,当您第一次单击tableWidget_uch时一切正常,并且open_uch_Window window 打开并且调用returnPressed事件时,它仅显示 1 次 1 次登录。 output button clicked,login dimarom4单击output按钮,登录 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但是当我点击tableWidget_uch并第二次打开open_uch_Window window 并调用returnPressed事件时,它返回两次“print('button clicked,login',login)':第一次来自过去的 login1 调用,第二次来自这次调用登入2

output button clicked,login dimarom4 button clicked,login zayaz output单击按钮,登录 dimarom4 单击按钮,登录 zayaz

how to make it correct?如何使它正确? so that each returnPressed.connect connects only once to the button这样每个returnPressed.connect只连接一次button

I use self.uch_info.ui.lineEdit.returnPressed.disconect() after print in button我在buttonprint后使用self.uch_info.ui.lineEdit.returnPressed.disconect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM