[英]How to Enable Button if there is Item in ComboBox in pyqt5?
嗨,在這張圖片中,我想在組合框中出現 USB 名稱時啟用開始按鈕,如果名稱沒有出現,按鈕應該自動禁用,這是我的代碼。
def x(self):
if (self.comboBox_3.currentIndex() == -1):
self.pushButton_5.setEnabled(False)
else:
self.pushButton_5.setEnabled(True)
您必須使用 currentIndexChanged 信號來評估該邏輯:
# __init__ method
# ...
self.comboBox_3.currentIndexChanged[int].connect(self.on_currentIndexChanged)
def on_currentIndexChanged(self, index):
self.pushButton_5.setEnabled(index != -1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.