简体   繁体   中英

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.

I did i increament , but label1 could not show new string its keep old string . label1 should update itself when I increamented the i value

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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