本文介紹了PyQt組合框更改標簽的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 PyQt5 為項目制作 UI.
I'm using PyQt5 to make a UI to a project.
當用戶更改組合框的值時,我想更改標簽的值.
I want to change the value of a label when the user changes the value of a combo box.
誰能幫我找出用來觸發"改變標簽值的函數的方法?
Can anyone help me to find out wich method to use to 'trigger' the function that changes the value of the label ?
推薦答案
如果是combo box的信號,當它的值改變時,可以使用
If you mean the signal of combo box, when it's value changed, you can use
QComboBox.currentTextChanged
或
QComboBox.currentIndexChanged
每次用戶更改組合框時,都會觸發這些信號.
Everytime a combobox is changed by user, these signals will be triggered.
假設 cb_1
是您的組合框父/小部件類中的一個簡單函數,例如
Suppose cb_1
is your combobox
a simple function in you parent/widget class like
def on_combobox_changed(self, value):
print("combobox changed", value)
# do your code
只是
cb_1.currentTextChanged.connect(self.on_combobox_changed)
嘗試更改組合框,看看會發生什么
try to change the combobox and see what will happen
這篇關于PyQt組合框更改標簽的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!