简体   繁体   English

如何在Pyside中打开一个新窗口

[英]How to open a new window in pyside

I am a beginner in Python as well as pyside. 我是python和pyside的新手。 I have a .ui file and I want to open it as a second window on clicking a button in main window. 我有一个.ui文件,我想在单击主窗口中的按钮时将其作为第二个窗口打开。 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). ...这是用于某些字符串输入(QInputDialog)的最简单对话框。 If you need more demanding dialog (and you will, sooner or later), you should use QDialog base class. 如果您需要更苛刻的对话框(您迟早需要),则应使用QDialog基类。 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. 在PySide DOCS上,几乎所有内容都可以很好地解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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