簡體   English   中英

pyqt5 連接按鈕按下堆疊小部件

[英]pyqt5 connecting button press to a stackedWidget

我剛剛將 my.ui 文件轉換為 py 文件,並嘗試使用信號和插槽系統將QPushButton鏈接到QStackedWidget 這就是我試圖做的:

self.createButton.clicked.connect(self.stackedWidget.setCurrentIndex(2)) 

並且應該在單擊按鈕時將堆疊小部件的索引設置為 2。 但是在運行時出現以下錯誤:

TypeError: argument 1 has unexpected type 'NoneType'

不太確定參數 1 是什么,但占位符代碼如下:

self.createButton.clicked.connect(self.stackedWidget.update)

似乎有效,但那不是我想要實現的。 我的代碼有什么問題?

the the connect function takes as a parameter a function to call when the click event is emited so you should wrap your statment in a lambda function as follows:

self.createButton.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(2)) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM