• <legend id='0iXoL'><style id='0iXoL'><dir id='0iXoL'><q id='0iXoL'></q></dir></style></legend>
      <bdo id='0iXoL'></bdo><ul id='0iXoL'></ul>

    1. <i id='0iXoL'><tr id='0iXoL'><dt id='0iXoL'><q id='0iXoL'><span id='0iXoL'><b id='0iXoL'><form id='0iXoL'><ins id='0iXoL'></ins><ul id='0iXoL'></ul><sub id='0iXoL'></sub></form><legend id='0iXoL'></legend><bdo id='0iXoL'><pre id='0iXoL'><center id='0iXoL'></center></pre></bdo></b><th id='0iXoL'></th></span></q></dt></tr></i><div id='0iXoL'><tfoot id='0iXoL'></tfoot><dl id='0iXoL'><fieldset id='0iXoL'></fieldset></dl></div>

        <tfoot id='0iXoL'></tfoot>
      1. <small id='0iXoL'></small><noframes id='0iXoL'>

        在 Python (PyQt4) 中显示弹出窗口

        时间:2023-10-09

            <legend id='L4PIM'><style id='L4PIM'><dir id='L4PIM'><q id='L4PIM'></q></dir></style></legend>

              • <bdo id='L4PIM'></bdo><ul id='L4PIM'></ul>

                  <i id='L4PIM'><tr id='L4PIM'><dt id='L4PIM'><q id='L4PIM'><span id='L4PIM'><b id='L4PIM'><form id='L4PIM'><ins id='L4PIM'></ins><ul id='L4PIM'></ul><sub id='L4PIM'></sub></form><legend id='L4PIM'></legend><bdo id='L4PIM'><pre id='L4PIM'><center id='L4PIM'></center></pre></bdo></b><th id='L4PIM'></th></span></q></dt></tr></i><div id='L4PIM'><tfoot id='L4PIM'></tfoot><dl id='L4PIM'><fieldset id='L4PIM'></fieldset></dl></div>

                  <small id='L4PIM'></small><noframes id='L4PIM'>

                • <tfoot id='L4PIM'></tfoot>

                    <tbody id='L4PIM'></tbody>
                  本文介绍了在 Python (PyQt4) 中显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我需要知道如何在用户单击按钮时弹出对话框.

                  I need to know how to be able to make a dialog pop-up when a user clicks a button.

                  我对 Python 和 PyQt/QtDesigner 都比较陌生.我只在其中使用了大约一个月,但我认为我掌握得很好.

                  I'm relatively new to both Python and PyQt/QtDesigner. I've only been using in them for about a month, but I think I have a good grasp.

                  这是我所拥有的:我在 QtDesigner 中设计的主对话框(它是应用程序的主要部分).我使用 pyuic4easy 将 .ui 转换为 .py.

                  Here's what I have: A main dialog (which is the main part of the application), which I designed in QtDesigner. I converted the .ui to .py using pyuic4easy.

                  这就是我想要做的:在 QtDesigner 中设计一个新对话框,并以某种方式使其在用户单击第一个(主)对话框上的按钮时弹出.

                  Here's what I want to do: design a new dialog box in the QtDesigner and somehow make it pop up when a user clicks a button on the first (main) dialog.

                  这是我的主对话框的代码:

                  Here's the code for my main dialog:

                  import sys
                  from PyQt4.QtCore import *
                  from loginScreen import *
                  
                  
                  class MyForm(QtGui.QDialog):
                  
                      def __init__(self, parent=None):
                          QtGui.QWidget.__init__(self, parent)
                          self.ui = Ui_Dialog()
                          self.ui.setupUi(self)
                          QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.popup)     
                          ...
                  
                          ... Some functions ...
                  
                     def popup(self):
                          #Pop-up the new dialog
                  
                  if __name__ == "__main__":
                     app = QtGui.QApplication(sys.argv)
                     myapp= MyForm()
                     myapp.show()
                     sys.exit(app.exec_())
                  

                  如您所见,我已将第一个按钮连接到一个名为popup"的方法,该方法需要填写代码以使我的第二个窗口弹出.我该怎么做呢?请记住,我已经在 QtDesigner 中设计了第二个对话框,我不需要创建新的.

                  So as you can see, I've connected the first button to a method named 'popup', which needs to be filled in with code to make my second window pop up. How do I go about doing this? Remember that I already have designed my second dialog in QtDesigner, and I don't need to create a new one.

                  感谢大家的帮助!

                  推荐答案

                  如您所见,我已将第一个按钮连接到名为'popup',需要填写代码才能使我的第二个弹出窗口.我该怎么做?

                  So as you can see, I've connected the first button to a method named 'popup', which needs to be filled in with code to make my second window pop up. How do I go about doing this?

                  与主窗口 (MyForm) 的操作方式几乎相同.

                  Pretty much the same way you do it for your main window (MyForm).

                  像往常一样,您为第二个对话框的 QtDesigner 代码编写一个包装类(就像您对 MyForm 所做的那样).我们称之为MyPopupDialog.然后在您的 popup 方法中,您创建一个实例,然后使用 exec_()show() 显示您的实例,具体取决于您是否想要模态或非模态对话框.(如果不熟悉 Modal/Modeless 的概念,可以参考 文档.)

                  As usual, you write a wrapper class for your QtDesigner code for the second dialog (like you did with MyForm). Let's call it MyPopupDialog. Then in your popup method, you create an instance and then show your instance with either exec_() or show() depending whether you want a modal or modeless dialog. (If you are not familiar with Modal/Modeless concept, you might refer to the documentation.)

                  所以整体可能看起来像这样(有一些修改):

                  So the overall thing might look like this (with a couple of modifications):

                  # Necessary imports
                  
                  class MyPopupDialog(QtGui.QDialog):
                      def __init__(self, parent=None):
                          # Regular init stuff...
                          # and other things you might want
                  
                  
                  class MyForm(QtGui.QDialog):
                      def __init__(self, parent=None):
                          # Here, you should call the inherited class' init, which is QDialog
                          QtGui.QDialog.__init__(self, parent)
                  
                          # Usual setup stuff
                          self.ui = Ui_Dialog()
                          self.ui.setupUi(self)
                  
                          # Use new style signal/slots
                          self.ui.pushButton.clicked.connect(self.popup)     
                  
                          # Other things...
                  
                     def popup(self):
                          self.dialog = MyPopupDialog()
                  
                          # For Modal dialogs
                          self.dialog.exec_()
                  
                          # Or for modeless dialogs
                          # self.dialog.show()
                  
                  if __name__ == "__main__":
                     app = QtGui.QApplication(sys.argv)
                     myapp= MyForm()
                     myapp.show()
                     sys.exit(app.exec_())
                  

                  这篇关于在 Python (PyQt4) 中显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:“wait_window"是什么意思?方法呢? 下一篇:Pyjnius 导入 jar 文件

                  相关文章

                  最新文章

                • <small id='i6BS8'></small><noframes id='i6BS8'>

                      <bdo id='i6BS8'></bdo><ul id='i6BS8'></ul>

                      <i id='i6BS8'><tr id='i6BS8'><dt id='i6BS8'><q id='i6BS8'><span id='i6BS8'><b id='i6BS8'><form id='i6BS8'><ins id='i6BS8'></ins><ul id='i6BS8'></ul><sub id='i6BS8'></sub></form><legend id='i6BS8'></legend><bdo id='i6BS8'><pre id='i6BS8'><center id='i6BS8'></center></pre></bdo></b><th id='i6BS8'></th></span></q></dt></tr></i><div id='i6BS8'><tfoot id='i6BS8'></tfoot><dl id='i6BS8'><fieldset id='i6BS8'></fieldset></dl></div>
                    1. <legend id='i6BS8'><style id='i6BS8'><dir id='i6BS8'><q id='i6BS8'></q></dir></style></legend>
                    2. <tfoot id='i6BS8'></tfoot>