2012-04-03 151 views
0

我想要創建一個代碼,它將顯示一個窗口的按鈕,點擊後會創建另一個窗口的一些字段(如QLabel,QLineEdit,QSpinBox等)。不過,我不知道如何創建一個彈出窗口...點擊按鈕彈出窗口

這裏是我的代碼:

#!/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_()) 
+1

我知道你在四月要求,可能已經轉移,但我一直在尋找的正是這種答案的說法。看看pyside示例代碼中的qdialog示例:http://qt.gitorious.org/pyside/pyside-examples查看示例/對話框中的代碼,我認爲您在尋找的是standarddialogs.py文件。 – James 2012-09-06 02:26:39

回答

0

我不知道這是不是最好的方式,但一個我能計算在夜裏出門......我希望它能幫助那些陷入類似問題的人。

所以,我(只是)創建爲第二個窗口單獨的代碼,並與

from subprocess import call 
call("./my_2nd_window_code.py")