Popup window on button click

Go To StackoverFlow.com

0

I want to create a code which will display a window with a button, which clicked will create another window with some fields (like QLabel, QLineEdit, QSpinBox, etc.). However, I don't know how to create that popup window...

Here is my code:

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

import sys                      # Needed for PySide
from PySide.QtCore import *
from PySide.QtGui import *

class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)

        # Create widgets
        self.label1 = QLabel("Label1")
        self.button_open = QPushButton("Open popup")

        self.button = QPushButton("Go!")
        self.qbtn = QPushButton('Quit')

        # Create layout and add widgets
        layout = QVBoxLayout()
        layout.addWidget(self.label1)
        layout.addWidget(self.button_open)

        # Buttons layout
        hbox_buttons = QHBoxLayout()
        hbox_buttons.addStretch(1)
        hbox_buttons.addWidget(self.button)
        hbox_buttons.addWidget(self.qbtn)

        # Main layout
        layout.addStretch(1)
        layout.addWidget(self.button_open)
        layout.addLayout(hbox_buttons)

        self.setLayout(layout)

        # Add buttons slots
        self.button_open.clicked.connect(self.popup)
        self.button.clicked.connect(self.function_runner)
        self.qbtn.clicked.connect(QCoreApplication.instance().quit)


    def popup (self, parent=__init__):
        new_win = # I wonder what should be here

if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)

    # Create and show the form
    form = Form()
    form.show()

    # Run the main Qt loop
    sys.exit(app.exec_())
2012-04-03 20:21
by Pawel Biernacki
I know you asked in April and may have moved on but I was looking for exactly this answer. Have a look at the qdialog examples in the pyside examples code: http://qt.gitorious.org/pyside/pyside-examples Check out the code in examples/dialogs, I think what you looking for is in the standarddialogs.py file - James 2012-09-06 02:26


0

I don't know if this is the best way, but the one I could figure out over the night... I hope it will help someone who got stuck with a similar problem.

So, I (simply) created a separate code for that second window and called it with

from subprocess import call
call("./my_2nd_window_code.py")
2012-04-04 17:18
by Pawel Biernacki