I have a list:
files = ["image1.png", "image2.png", "image3.png", "image4.png", "image5.png", "image6.png"]
And PyQt5 buttons and a label:
How can I have the first item of the list on the label and go through the list one by one with the:
Next button (click, image2.png, click, image3.png, click, image4.png...)
Previous button (click, image3.png, click, image2.png, click, image1.png...)
And the label should update accordingly.
I've tried all day and searched for answers but couldn't get it to work. This could help maybe, my skills weren't enough to utilize the advice, though.
All the code to create the above window with buttons:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App(QWidget):
def __init__(self):
super().__init__()
self._files = deque()
self._filesCount = len(self._files)
self._setupUI()
self._connectSignalsSlots()
def __init__(self):
super().__init__()
self.title = 'PyQt5 button - pythonspot.com'
self.left = 10
self.top = 10
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('Print Files List', self)
button.move(100,70)
button.clicked.connect(self.loadFiles)
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('Print Next Filename', self)
button.move(160,110)
button.clicked.connect(self.nextFilename)
label = QLabel('image1.png (should be first of the list, \n and update with button presses)', self)
label.move(35,140)
button = QPushButton('Print Previous Filename', self)
button.move(10,110)
button.clicked.connect(self.previousFilename)
self.show()
@pyqtSlot()
def loadFiles(self):
files = ["image1.png", "image2.png", "image3.png", "image4.png", "image5.png", "image6.png"]
if len(files) > 0:
for file in files:
print(file)
def nextFilename(self):
print('nextFilenameButton click')
def previousFilename(self):
print('previousFilenameButton click')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())