简体   繁体   中英

How to open a new window in pyside

I am a beginner in Python as well as pyside. I have a .ui file and I want to open it as a second window on clicking a button in main window. I used this code but it closes the main window perhaps because of "self". Please help me out.

class PhoneBook:

   def __init__(self):
        loader = QUiLoader();       
        file = QFile("PhoneBook.ui");   
        file.open(QFile.ReadOnly);  
        self.ui = loader.load(file);    
        file.close();           
        self.ui.pushButton.clicked.connect(self.add);

  def __del__ ( self ):
        self.ui = None;

  def add(self):
        loader1 = QUiLoader();      
        file1 = QFile("Add.ui");    
        file1.open(QFile.ReadOnly); 
        self.ui = loader1.load(file1);  
        file1.close();          
        self.ui.show();

  def show(self):
        self.ui.show();

I'm noob too. About how to make dialog, I think your point is input dialog where you want to enter data for that phonebook. The easiest way I found is such :

txtLabel = "Put some value into dialog"
inputText, ok = QInputDialog.getText(self, "Dialog Name", txtLabel)
if ok:
    print ".........."
    print inputText

...and that's for the simplest dialog for some string input (QInputDialog). If you need more demanding dialog (and you will, sooner or later), you should use QDialog base class. In that case what exactly you want to put into it, how it will looks like and everything about it's behaviour. On PySide DOCS almost everything is nice explained.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM