I
I
Ignat Biroev2021-12-02 03:20:13
PyQt
Ignat Biroev, 2021-12-02 03:20:13

How to make it so that different actions are performed inside one widget?

How can you make it so that in the application, when you click the first button in the ListWidget, a list of names of pictures in the folder along the selected path is displayed, and when you click the second script, it takes these pictures and converts them to PDF?

import os
import sys

import img2pdf
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QFileDialog
import ui_window


class App(QtWidgets.QMainWindow, ui_window.Ui_MainWindow):
    def __init__(self):
        super(App, self).__init__()
        self.setupUi(self)
        self.btn_choose.clicked.connect(self.listWidget)
        # btn_convert.clicked.connect(self.listWidget)

    def btn_choose(self):
        self.plainTextEdit.clear()
        path = QFileDialog.getExistingDirectory(self, "Выберите файлы")

        if path:
            for files in os.listdir(path):
                self.listWidget.addItem(files)


def main():
    app = QtWidgets.QApplication(sys.argv)
    window = App()
    window.show()

    app.exec_()


if __name__ == "__main__":
    main()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-12-04
@Vindicar

> the button took a directory from the first button
And here and on a jamb. Not from the "first button", but from a specially created (in __init__() of course) field of the Convert_App class. And the handler for pressing the first button should write data to this field.
These are the basics of Python OOP, master them and such questions will not arise.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question