N
N
Niriter Inc.2017-07-18 19:00:58
Python
Niriter Inc., 2017-07-18 19:00:58

Buttons in PYQT5?

how to make a window with a button after clicking on the button, another 1 button appears next to it
UPD: Here is a sketch, but it doesn’t add a button, although somehow I didn’t change it, didn’t add or delete something:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog,
        QDialogButtonBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
        QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QSpinBox, QTextEdit,
        QVBoxLayout)
 
import sys
 
class Dialog(QDialog):

    def __init__(self):
        super(Dialog, self).__init__()   
        global layout
        layout = QVBoxLayout()   
        button=QPushButton("Click", self)
        button.move(50, 50)
        button.clicked.connect(self.sloter)
        self.show()
 
    def sloter(self):
        global button2
        self.button2 = QPushButton("Clicker", self)
        self.button2.move(70, 70)
        layout.addWidget(self.button2)
        self.show()
 

 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = Dialog()
sys.exit(dialog.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2017-07-18
@niriter

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog,
                             QDialogButtonBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
                             QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QSpinBox, QTextEdit,
                             QVBoxLayout)

import sys


class Dialog(QDialog):
    def __init__(self):
        super(Dialog, self).__init__()
        global layout
        layout = QVBoxLayout()
        button = QPushButton("Click", self)
        button.move(50, 50)
        button.clicked.connect(self.sloter)

        button2 = QPushButton("Clicker", self)
        button2.move(50, 100)
        button2.hide()
        self.button2 = button2
        self.show()

    def sloter(self):
        self.button2.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = Dialog()
sys.exit(dialog.exec_())

God save me from shitty code
====
Your problem here is thecodeinn.blogspot.com/2013/09/dynamically-adding...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question