<bdo id='k8HZ7'></bdo><ul id='k8HZ7'></ul>
<legend id='k8HZ7'><style id='k8HZ7'><dir id='k8HZ7'><q id='k8HZ7'></q></dir></style></legend>
  • <tfoot id='k8HZ7'></tfoot>

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

        <i id='k8HZ7'><tr id='k8HZ7'><dt id='k8HZ7'><q id='k8HZ7'><span id='k8HZ7'><b id='k8HZ7'><form id='k8HZ7'><ins id='k8HZ7'></ins><ul id='k8HZ7'></ul><sub id='k8HZ7'></sub></form><legend id='k8HZ7'></legend><bdo id='k8HZ7'><pre id='k8HZ7'><center id='k8HZ7'></center></pre></bdo></b><th id='k8HZ7'></th></span></q></dt></tr></i><div id='k8HZ7'><tfoot id='k8HZ7'></tfoot><dl id='k8HZ7'><fieldset id='k8HZ7'></fieldset></dl></div>
      1. 在字符串中按下 QpushButton 时如何在 QlineEdit 中获

        时间:2023-08-07
        <i id='6zlog'><tr id='6zlog'><dt id='6zlog'><q id='6zlog'><span id='6zlog'><b id='6zlog'><form id='6zlog'><ins id='6zlog'></ins><ul id='6zlog'></ul><sub id='6zlog'></sub></form><legend id='6zlog'></legend><bdo id='6zlog'><pre id='6zlog'><center id='6zlog'></center></pre></bdo></b><th id='6zlog'></th></span></q></dt></tr></i><div id='6zlog'><tfoot id='6zlog'></tfoot><dl id='6zlog'><fieldset id='6zlog'></fieldset></dl></div>
            <tfoot id='6zlog'></tfoot>
            • <bdo id='6zlog'></bdo><ul id='6zlog'></ul>

              <small id='6zlog'></small><noframes id='6zlog'>

                  <tbody id='6zlog'></tbody>
                  <legend id='6zlog'><style id='6zlog'><dir id='6zlog'><q id='6zlog'></q></dir></style></legend>
                  本文介绍了在字符串中按下 QpushButton 时如何在 QlineEdit 中获取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试实现一个功能.我的代码如下.

                  I am trying to implement a function. My code is given below.

                  当用户单击名称为连接"的按钮时,我想在字符串中获取对象名称为主机"的文本,例如主机".我怎样才能做到这一点?我尝试过,但失败了.如何实现这个功能?

                  I want to get the text in lineedit with objectname 'host' in a string say 'shost' when the user clicks the pushbutton with name 'connect'. How can I do this? I tried and failed. How do I implement this function?

                  import sys
                  from PyQt4.QtCore import *
                  from PyQt4.QtGui import *
                  
                  
                  class Form(QDialog):
                      def __init__(self, parent=None):
                          super(Form, self).__init__(parent)
                  
                          le = QLineEdit()
                          le.setObjectName("host")
                          le.setText("Host")
                          pb = QPushButton()
                          pb.setObjectName("connect")
                          pb.setText("Connect") 
                          layout.addWidget(le)
                          layout.addWidget(pb)
                          self.setLayout(layout)
                  
                          self.connect(pb, SIGNAL("clicked()"),self.button_click)
                  
                          self.setWindowTitle("Learning")
                  
                      def button_click(self):
                      #i want the text in lineedit with objectname 
                      #'host' in a string say 'shost'. when the user click 
                      # the pushbutton with name connect.How do i do it?
                      # I tried and failed. How to implement this function?
                  
                  
                  
                  
                  app = QApplication(sys.argv)
                  form = Form()
                  form.show()
                  app.exec_()
                  

                  现在如何实现button_click"功能?我刚刚开始使用 pyQt!

                  Now how do I implement the function "button_click" ? I have just started with pyQt!

                  推荐答案

                  我的第一个建议是使用 Qt Designer 来创建你的 GUI.自己打字很糟糕,需要更多时间,而且你肯定会比 Qt Designer 犯更多的错误.

                  My first suggestion is to use Qt Designer to create your GUIs. Typing them out yourself sucks, takes more time, and you will definitely make more mistakes than Qt Designer.

                  这里有一些 PyQt 教程 帮助您走上正轨.列表中的第一个是您应该开始的地方.

                  Here are some PyQt tutorials to help get you on the right track. The first one in the list is where you should start.

                  了解哪些方法可用于特定类的一个很好的指南是 PyQt4 类参考.在这种情况下,您将查找 QLineEdit 并看到有一个 text 方法.

                  A good guide for figuring out what methods are available for specific classes is the PyQt4 Class Reference. In this case, you would look up QLineEdit and see the there is a text method.

                  回答您的具体问题:

                  要使您的 GUI 元素可用于对象的其余部分,请在它们前面加上 self.

                  To make your GUI elements available to the rest of the object, preface them with self.

                  import sys
                  from PyQt4.QtCore import SIGNAL
                  from PyQt4.QtGui import QDialog, QApplication, QPushButton, QLineEdit, QFormLayout
                  
                  class Form(QDialog):
                      def __init__(self, parent=None):
                          super(Form, self).__init__(parent)
                  
                          self.le = QLineEdit()
                          self.le.setObjectName("host")
                          self.le.setText("Host")
                          
                          self.pb = QPushButton()
                          self.pb.setObjectName("connect")
                          self.pb.setText("Connect") 
                          
                          layout = QFormLayout()
                          layout.addWidget(self.le)
                          layout.addWidget(self.pb)
                  
                          self.setLayout(layout)
                          self.connect(self.pb, SIGNAL("clicked()"),self.button_click)
                          self.setWindowTitle("Learning")
                  
                      def button_click(self):
                          # shost is a QString object
                          shost = self.le.text()
                          print shost
                          
                  
                  app = QApplication(sys.argv)
                  form = Form()
                  form.show()
                  app.exec_()
                  

                  这篇关于在字符串中按下 QpushButton 时如何在 QlineEdit 中获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Pylint 中的模块“PyQt5.QtWidgets"错误中没有名称 下一篇:使用 Qt Designer 表单和 PyQt5 在 QWidget 中绘制 matp

                  相关文章

                  最新文章

                  <legend id='Qr1Zt'><style id='Qr1Zt'><dir id='Qr1Zt'><q id='Qr1Zt'></q></dir></style></legend>
                • <small id='Qr1Zt'></small><noframes id='Qr1Zt'>

                  <tfoot id='Qr1Zt'></tfoot>
                    • <bdo id='Qr1Zt'></bdo><ul id='Qr1Zt'></ul>

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