working on it ...


Explore Public Snippets

Sort by

Found 1 snippet matching: "dynamic creation in pyqt4"

    public by lbottaro  5987  44  7  0

    How to dynamically add a button to a GUI mask in python using PyQt4

    This code shows how to add some dynamic GUI controls (in this case QPushButton) to a GUI main window. In this example when user clicks on a button, the new buttons are created and put into the main window.
    import sys
    from PyQt4 import QtGui
    import os
    class Test(QtGui.QMainWindow):  
        def __init__(self):
            super(Test, self).__init__()
        def initUI(self):
            YDrive = QtGui.QAction("Y", self)
            self.toolbar = self.addToolBar('Exit')
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Message box')    
        def buttonClicked(self):
            print "clicked"
        def setYDir(self):
            myWorkDrive = "/tmp"
            shows = os.listdir(myWorkDrive)
            i = 0
            for elements in shows:
                btn1 = QtGui.QPushButton(elements, self)
                btn1.move(30, 50 + i)
                i += 30
            self.resize(self.width(), 50 + i)
    if __name__ == '__main__':
        app = QtGui.QApplication([])
        t = Test()

    List Complete ( 1 snippet total )

    Cannot find what you were looking for?
    Ask the Snip2Code Community

    • Public Snippets
    • Channels Snippets