标签
self.titlelabel = QLabel(self)
self.artistlabel = QLabel(self)
self.albumlabel = QLabel(self)
在UI中,当我运行方法时不更新。
我的意思是,它们确实处理initUI(self)
的初始初始化,但是当我更改组合框中的项时,不会用新信息更新
我在initUI(self)
中运行这个命令,它连接到dropdown/Qcombobox self.cb.activated.connect(self.updateTrackInfo)
def currentTrackInfo(self):
currentTrackInfoDict = {}
currentZone = str(self.cb.currentText())
deviceDict = self.sonosZonesCoordinatorsIP()
for key, value in deviceDict.items():
if value == currentZone:
device = SoCo(key)
track = device.get_current_track_info()
current_title = track['title']
current_artist = track["artist"]
current_album = track["album"]
currentTrackInfoDict.update({"current_title":current_title})
currentTrackInfoDict.update({"current_artist":current_artist})
currentTrackInfoDict.update({"current_album":current_album})
return currentTrackInfoDict
def updateTrackInfo(self):
self.currentTrackInfoDict = self.currentTrackInfo()
self.titlelabel = QLabel(self)
self.artistlabel = QLabel(self)
self.albumlabel = QLabel(self)
self.titlelabel.move((PLAYICONHEIGHT-100),(WINDOWHEIGHT-230))
self.artistlabel.move((PLAYICONHEIGHT-100),(WINDOWHEIGHT-220))
self.albumlabel.move((PLAYICONHEIGHT-100),(WINDOWHEIGHT-250))
self.titlelabel.setText("Title: {}".format(self.currentTrackInfoDict["current_title"]))
print(self.currentTrackInfoDict["current_title"])
self.artistlabel.setText("Artist: {}".format(self.currentTrackInfoDict["current_artist"]))
self.albumlabel.setText("Album: {}".format(self.currentTrackInfoDict["current_album"]))
print函数:print(self.currentTrackInfoDict["current_title"])
-工作,但是标签没有更新。你知道吗
先谢谢你。你知道吗
在
updateTrackInfo
方法中,每次创建新的QLabel
对象时,都要更新现有对象上的文本。这可能会导致问题,因为新标签与旧标签重叠(您没有删除旧标签,它们在调用updateTrackInfo
后仍然存在)。我建议搬家进入
__init__(self)
方法,并在updateTrackInfo
方法中只保留标签更新代码currentIndexChanged
QComboBox
信号代替activated
相关问题 更多 >
编程相关推荐