5
PyQt 버튼 이벤트는 함수에 일반적인 방법으로 연결되어 함수가 기본 신호 인수 (이 경우 버튼 확인 상태)를 수신 할 수 있습니다.기본 신호 인수를 잃지 않고 여분의 인수를 PyQt 슬롯에 전달하십시오.
def connections(self):
my_button.clicked.connect(self.on_button)
def on_button(self, checked):
print checked # prints "True"
또는 기본 신호 인수가 lambda
을 사용하여 대체 할 수 있습니다 : 그것은 바로 아래 같은 기능을 수신 할 수 있도록 두 신호 인수를 유지하는 좋은 방법이
def connections(self):
my_button.clicked.connect(lambda: self.on_button('hi'))
def on_button(self, message):
print message # prints "hi"
있습니까?
def on_button(self, checked, message):
print checked, message # prints "True, hi"
당신은 버튼을 하위 클래스를하고의 상태를 방출하는 새로운 신호를 생성 버튼과 메시지. – SnoozeTime
[Eli Bendersky] (https://eli.thegreenplace.net) [이 기사에 대한 글] (https://eli.thegreenplace.net/2011/04/25/passing-extra-arguments-to-pyqt- 슬롯). – delrocco