简体   繁体   English

按钮后刷新Python Pyqt5 Qlabel单击

[英]Python Pyqt5 Qlabel refreshing after button Click

I wrote a simple code in Python GUI using PYQT5 , I want to do when I click a correct button (exp. "Das" is correct) i increament itself '1' and also "label1" must show new artikel[i+1] value. 我使用PYQT5在Python GUI中编写了一个简单的代码,当我单击一个正确的按钮(例如“ Das”是正确的)时,我想这样做,但自身的状态为'1',并且“ label1”也必须显示新的artikel [i + 1]值。

I did i increament , but label1 could not show new string its keep old string . 我确实没打过招,但是label1无法显示新字符串,而保留旧字符串。 label1 should update itself when I increamented the i value 我对i值不满意时,label1应该会更新

Thanks in advance 提前致谢

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_())

SOLVED 解决了

button3.clicked.connect(self.on_click3) goes to under def on_click3(self): and going inside if (DataF['artikel'][self.i] == "das"): if that condition correct , it should return this return self.label1.setText(DataF['Wort'][self.i])) and label1 changes easily. 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容易更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM