我使用PYQT5在Python GUI中编写了一个简单的代码,当我单击一个正确的按钮(exp。“ Das”是正确的)时,我想这样做,但自身的状态为'1',并且“ label1”也必须显示新的artikel [i +1]值。
我确实没打过招,但是label1不能显示新字符串,而保留旧字符串。我对i值不满意时,label1应该会自动更新
预先感谢
import pandas as pd
import xlrd as xl
from pandas import ExcelWriter
from pandas import ExcelFile
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import *
from PyQt5.QtGui import *
DataF=pd.read_excel("/home/emir/Masaüstü/artikel.xlsx")
print("Column headings:")
print(DataF.columns)
for q in DataF.index:
print(DataF['artikel'][q])
for q in DataF.index:
print(DataF['Wort'][q])
for q in DataF.index:
print(DataF['Plural'][q])
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Deutsch Lern'
self.left = 10
self.top = 100
self.width = 320
self.height = 200
self.i=0
self.a=False
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('Der', self)
button.setToolTip('Kontrol Et')
button.move(20, 160)
button.clicked.connect(self.on_click)
button2 = QPushButton('Die', self)
button2.setToolTip('Kontrol Et')
button2.move(110, 160)
button2.clicked.connect(self.on_click2)
button3 = QPushButton('Das', self)
button3.setToolTip('Kontrol Et')
button3.move(200, 160)
button3.clicked.connect(self.on_click3)
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Create textbox
self.label1 = QLabel(DataF['Wort'][self.i], self)
self.label1.move(130, 80)
#if (self.a == True):
# self.label2 = QLabel(DataF['Wort'][self.i], self)
# self.i += 1
# self.label2.move(13, 80)
# self.show()
# I tried create new label when a=True.didn't work.
self.show()
@pyqtSlot()
def on_click(self):
if(DataF['artikel'][self.i]=="der"):
#print(DataF['Plural'][1])
print('dogru')
a=True
self.i+=1
else:
print("yanlış")
def on_click2(self):
if (DataF['artikel'][self.i] == "die"):
print('dogru')
a=True
self.i+=1
else:
print("yanlış")
def on_click3(self):
if (DataF['artikel'][self.i] == "das"):
print('dogru')
a=True
self.i+=1
#self.art()
print(self.i)
else:
print("yanlış")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
答案 0 :(得分:0)
已解决
button3.clicked.connect(self.on_click3)
转到def on_click3(self):
下,如果出现这种情况,则进入if (DataF['artikel'][self.i] == "das"):
正确,它应该返回此return self.label1.setText(DataF['Wort'][self.i]))
并且label1容易更改。