如何更改通过按按钮显示的标签蜂? 通过在消息框中按一个按钮可以调用该函数。 我已经尝试过setCurrentIndex(),但是显示的标签蜂不会改变。
我正在使用Pyhton 3.6和pyqt5。
这是我的代码:
import pandas as pd
"""Natahuje data"""
df = pd.read_csv('C:/Users/I5/Desktop/SPY.csv')
"""Dava data do pandy"""
spracovane = pd.DataFrame(df)
"""Pocita dennu zmennu z Adj Close"""
zmena = pd.DataFrame.pct_change(spracovane["Adj Close"])
"""Vytvara novy stlpec s dennou zmenou"""
spracovane["% change"] = zmena
"""Sortuje najvacsie denne zmeny"""
zoradene = spracovane.sort_values(by=["% change"], ascending = True,)
"""Finalna podoba tabulky"""
tabulka = zoradene[["Date", "% change"]]
for c in tabulka["% change"]:
if c >= 0.05:
print(c)
if c <= -0.05:
print (c)
答案 0 :(得分:1)
尝试一下:
import sys
from PyQt5 import QtWidgets, QtCore, QtPrintSupport, QtGui
from PyQt5.QtWidgets import *
class main_window(QTabWidget):
def __init__(self, parent=None):
super(QTabWidget, self).__init__(parent)
self.setGeometry(50, 50, 1100, 750)
self.setWindowTitle("Programm") #
self.centralWidget = QtWidgets.QWidget()
self.tabWidget = QtWidgets.QTabWidget(self.centralWidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 10, 1200, 1000))
self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.West)
self.tab_v1 = QtWidgets.QWidget()
self.addTab(self.tab_v1, "Tab 1")
self.tab_v2 = QtWidgets.QWidget()
self.addTab(self.tab_v2, "Tab 2")
self.tab_v3 = QtWidgets.QWidget()
self.addTab(self.tab_v3, "Tab 3")
self.openFile = QPushButton("Choose Tab ", self.tab_v1)
self.openFile.setGeometry(QtCore.QRect(700, 25, 200, 30))
self.openFile.clicked.connect(self.on_click_do)
def on_click_do(self):
box1 = QMessageBox()
box1.setIcon(QMessageBox.Question)
box1.setWindowTitle('Information')
box1.setText(
"Do you want to go to the next Tab?")
box1.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
buttonY = box1.button(QMessageBox.Yes)
buttonY.setText('Yes') ##translation
buttonN = box1.button(QMessageBox.No)
buttonN.setText('No') ## translation
box1.exec_()
if box1.clickedButton() == buttonN:
pass
elif box1.clickedButton() == buttonY:
#self.tabWidget.setCurrentIndex(1) # ---
self.setCurrentIndex(1) # +++
def main():
app = QApplication(sys.argv)
ex = main_window()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()