[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Doubt
From:       tanya tanyaradzwa <tanyatanyaradzwa460 () gmail ! com>
Date:       2019-10-24 15:11:50
Message-ID: CABO0HDGe+Pg9Z1eeQ-s+vscKSkzytaObBQR8p_MBWFGiXbHnew () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Dennis,

My apology for the late response, I was out of town.

Thank you for the code. I did run it, but the output gives the output as
depicted in the attached file. Please assist.


Warm regards

Tanya

On Mon, Oct 14, 2019 at 5:09 PM Dennis Jensen <djensen@pgcontrols.com>
wrote:

> Okay first of all what you posted did not execute due to a few typos and
> such so I went and rendered it and added a few adjustments:
> 
> import argparse
> 
> from sys    import exit   as sysExit
> from pprint import pprint
> 
> from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout
> from PyQt5.QtWidgets import QInputDialog, QLineEdit, QPushButton
> 
> # Okay because this Window is so simple there is no reason to
> # sub-class it beyond this however if it were a QMainWindow the
> # Center Widget would have been the main gui implementation and
> # QMainWindow would have been the Controller Class or Main
> # Application that coordinates all the elements between the Gui
> # and any Data Sources it might have
> class TutorialWindow(QWidget):
> # The Init had a typo
> def __init__(self):
> QWidget.__init__(self)
> 
> # Okay its a simple thing but every window ought to
> # have its own Title
> self.setWindowTitle('Tutorial Window')
> self.setGeometry(300, 300, 290, 140)
> 
> # Using the coordinate system is not PyQt as it was
> # designed to use the Layout system as follows
> self.btnOpen = QPushButton('Open')
> self.btnOpen.clicked.connect(self.showDialog)
> 
> self.lneTextName = QLineEdit()
> self.lneTextName.setPlaceholderText("Enter your name:")
> 
> # This is an invisible horizontal box to put these 2
> # widgets on the same line and because we want the
> # Textbox to expand with the window we do not tack a
> # Stretch object to it
> HBox = QHBoxLayout()
> HBox.addWidget(self.btnOpen)
> HBox.addWidget(self.lneTextName)
> 
> # This is a vertical which is only needed because IOError
> # wanted to place the previous objects at the top of the
> # layout so I add the above horizontal box to the vertical
> # box and follow it with a Stretch object
> VBox = QVBoxLayout()
> VBox.addLayout(HBox)
> VBox.addStretch(1)
> 
> # We could do this cryptically by passing objects into
> # other objects but I find that doing it explicitly helps
> # to make things more clean and clear
> self.setLayout(VBox)
> 
> # This was improperly indented (to far) it is part of the class
> # but should not be contained within the Init function
> def showDialog(self):
> text, result = QInputDialog.getText(self, 'Input Dialog', 'Enter
> your name:')
> if result == True:
> self.lneTextName.setText(str(text))
> 
> # Just an Argparse example snippet
> def GetCmdLineArgs():
> Parsr = argparse.ArgumentParser()
> Parsr.add_argument('echo')
> ArgVals = Parsr.parse_args()
> 
> return ArgVals
> 
> if __name__ == '__main__':
> # If you are going to do Command Line Arguments I would
> # strongly suggest you look into Argparse as it is the
> # recommended command-line standard Python parsing module
> CmdLneArgs = GetCmdLineArgs()
> pprint('Command Line Arguements = ' + CmdLneArgs.echo)
> 
> # Using Argparse means QApplication will never import any
> # command line objects as such we supply an empty list instead
> # Further what QApplication returns is your Main Application
> # Event Thread as such I name it accordingly to reduce any
> # potential confusion about its true purpose
> MainEvntThred = QApplication([])
> 
> # While this is often the Main Gui it really is the PyQt
> # Main Application especially if you get into any more
> # complicated Gui/Application renderings and thus again
> # I name it accordingly to reduce confusion about its
> # true purpose
> MainApp = TutorialWindow()
> MainApp.show()
> 
> sysExit(MainEvntThred.exec_())
> 
> On 10/12/2019 10:02 AM, tanya tanyaradzwa wrote:
> 
> Hello everyone,
> 
> Referring to the assignment question l asked for your assistance, please
> find my code herein, and attached is the output on my side. Thank you. Tanya
> 
> import sys
> from pprint import pprint
> from PyQt5.QtWidgets import QWidget, QPushButton, QInputDialog, QLineEdit,
> QApplication
> 
> class TutorialWindow(QWidget):
> def __init(self):
> super().__init__()
> self.btn = QPushButton('Open', self)
> self.btn.move(0, 20)
> self.btn.clicked.connect(self.showDialog)
> 
> self.text_name = QLineEdit(self)
> self.text_name.move(100, 22)
> self.text_name.setPlaceholderText("Enter your name:")
> 
> self.Geometry(300, 300, 290, 140)
> 
> def showDialog(self):
> text, result = QInputDialog.getText(self, 'Input Dialog',
> 'Enter your name:')
> if result ==True:
> self.text_name.setText(str(text))
> 
> if __name__ == '__main__':
> app = QApplication(sys.argv)
> pprint("input parameters  = " + str(sys.argv))
> tutorial_window = TutorialWindow()
> tutorial_window.show()
> sys.exit(app.exec_())
> 
> 
> On Oct 4, 2019 14:33, "tanya tanyaradzwa" <tanyatanyaradzwa460@gmail.com>
> wrote:
> 
> > Hi Florian,
> > 
> > Thank you for your response.
> > 
> > I will send to you my code and the output on my side.
> > 
> > On Oct 4, 2019 09:56, "Florian Bruhin" <me@the-compiler.org> wrote:
> > 
> > > Hey Tanya,
> > > 
> > > On Fri, Oct 04, 2019 at 08:50:50AM +0200, tanya tanyaradzwa wrote:
> > > > I am struggling with a school assignment. I have researched all places
> > > > online, but l am failing to bring it all together. Please assist me.
> > > > 
> > > > Question:
> > > > 
> > > > Create an application using PyQt. The user is prompted for the name of
> > > an
> > > > animal rescue service. This must be displayed in the UI in capital
> > > letters.
> > > > The user is then required to enter a character (letter). This must
> > > also be
> > > > displayed on the UI in capital letters. The application
> > > > must read the name of the animal rescue service as well as the
> > > character
> > > > and then count the number of occurrences of the character in the animal
> > > > rescue service name. The count must be displayed.
> > > > 
> > > > Also required:
> > > > 
> > > > Error message for incorrect input from user (e.g. no name of animal
> > > rescue
> > > > service).
> > > > Error message of character not found or the character is blank!
> > > > 
> > > > May you please assist. Thank you.
> > > 
> > > If you have some specific issues, people here would likely be happy to
> > > help.
> > > What do you have so far and where do you run into issues?
> > > 
> > > This pretty much boils down to "please do my homework for me", which at
> > > least
> > > I'm not going to do.
> > > 
> > > Florian
> > > 
> > > --
> > > https://www.qutebrowser.org | me@the-compiler.org (Mail/XMPP)
> > > GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
> > > I love long mails! | https://email.is-not-s.ms/
> > > 
> > 
> _______________________________________________
> PyQt mailing list    \
> PyQt@riverbankcomputing.comhttps://www.riverbankcomputing.com/mailman/listinfo/pyqt \
>  


[Attachment #5 (text/html)]

<div dir="ltr">Hi Dennis,<div><br></div><div>My apology for the late response, I was \
out of town.</div><div><br></div><div>Thank you for the code. I did run it, but the \
output gives the output as depicted in the attached file. Please \
assist.</div><div><br></div><div><br></div><div>Warm \
regards</div><div><br></div><div>Tanya</div></div><br><div class="gmail_quote"><div \
dir="ltr" class="gmail_attr">On Mon, Oct 14, 2019 at 5:09 PM Dennis Jensen &lt;<a \
href="mailto:djensen@pgcontrols.com">djensen@pgcontrols.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">  
    
  
  <div bgcolor="#FFFFFF">
    <p>Okay first of all what you posted did not execute due to a few
      typos and such so I went and rendered it and added a few
      adjustments:</p>
    <p><font size="-1" face="Courier New, Courier, monospace">import
        argparse</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">from sys      
        import exit     as sysExit</font><br>
      <font size="-1" face="Courier New, Courier, monospace">from pprint
        import pprint</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">from
        PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout,
        QVBoxLayout</font><br>
      <font size="-1" face="Courier New, Courier, monospace">from
        PyQt5.QtWidgets import QInputDialog, QLineEdit, QPushButton</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace"># Okay
        because this Window is so simple there is no reason to</font><br>
      <font size="-1" face="Courier New, Courier, monospace"># sub-class
        it beyond this however if it were a QMainWindow the</font><br>
      <font size="-1" face="Courier New, Courier, monospace"># Center
        Widget would have been the main gui implementation and</font><br>
      <font size="-1" face="Courier New, Courier, monospace">#
        QMainWindow would have been the Controller Class or Main</font><br>
      <font size="-1" face="Courier New, Courier, monospace">#
        Application that coordinates all the elements between the Gui</font><br>
      <font size="-1" face="Courier New, Courier, monospace"># and any
        Data Sources it might have</font><br>
      <font size="-1" face="Courier New, Courier, monospace">class
        TutorialWindow(QWidget):</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # The
        Init had a typo</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       def
        __init__(self):</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        QWidget.__init__(self)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        Okay its a simple thing but every window ought to</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        have its own Title</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.setWindowTitle(&#39;Tutorial Window&#39;)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.setGeometry(300, 300, 290, 140)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        Using the coordinate system is not PyQt as it was</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        designed to use the Layout system as follows</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.btnOpen = QPushButton(&#39;Open&#39;)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.btnOpen.clicked.connect(self.showDialog)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.lneTextName = QLineEdit()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.lneTextName.setPlaceholderText(&quot;Enter your name:&quot;)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        This is an invisible horizontal box to put these 2 </font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        widgets on the same line and because we want the </font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        Textbox to expand with the window we do not tack a </font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        Stretch object to it</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        HBox = QHBoxLayout()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        HBox.addWidget(self.btnOpen)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        HBox.addWidget(self.lneTextName)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        This is a vertical which is only needed because IOError</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        wanted to place the previous objects at the top of the </font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        layout so I add the above horizontal box to the vertical</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           # box
        and follow it with a Stretch object</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        VBox = QVBoxLayout()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        VBox.addLayout(HBox)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        VBox.addStretch(1)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">           # We
        could do this cryptically by passing objects into</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           #
        other objects but I find that doing it explicitly helps</font><br>
      <font size="-1" face="Courier New, Courier, monospace">           # to
        make things more clean and clear           </font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        self.setLayout(VBox)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">   # This
        was improperly indented (to far) it is part of the class</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # but
        should not be contained within the Init function</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       def
        showDialog(self):</font><br>
      <font size="-1" face="Courier New, Courier, monospace">              
        text, result = QInputDialog.getText(self, &#39;Input Dialog&#39;, &#39;Enter
        your name:&#39;)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">               if
        result == True:</font><br>
      <font size="-1" face="Courier New, Courier, monospace">                      
        self.lneTextName.setText(str(text))</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace"># Just an
        Argparse example snippet</font><br>
      <font size="-1" face="Courier New, Courier, monospace">def
        GetCmdLineArgs():</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       Parsr =
        argparse.ArgumentParser()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">      
        Parsr.add_argument(&#39;echo&#39;)</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       ArgVals
        = Parsr.parse_args()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       </font><br>
      <font size="-1" face="Courier New, Courier, monospace">       return
        ArgVals</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">if __name__
        == &#39;__main__&#39;:</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # If you
        are going to do Command Line Arguments I would</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   #
        strongly suggest you look into Argparse as it is the</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   #
        recommended command-line standard Python parsing module </font><br>
      <font size="-1" face="Courier New, Courier, monospace">      
        CmdLneArgs = GetCmdLineArgs()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">      
        pprint(&#39;Command Line Arguements = &#39; + CmdLneArgs.echo)</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">   # Using
        Argparse means QApplication will never import any</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # command
        line objects as such we supply an empty list instead</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # Further
        what QApplication returns is your Main Application</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # Event
        Thread as such I name it accordingly to reduce any</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   #
        potential confusion about its true purpose</font><br>
      <font size="-1" face="Courier New, Courier, monospace">      
        MainEvntThred = QApplication([])</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">   # While
        this is often the Main Gui it really is the PyQt </font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # Main
        Application especially if you get into any more </font><br>
      <font size="-1" face="Courier New, Courier, monospace">   #
        complicated Gui/Application renderings and thus again</font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # I name
        it accordingly to reduce confusion about its </font><br>
      <font size="-1" face="Courier New, Courier, monospace">   # true
        purpose</font><br>
      <font size="-1" face="Courier New, Courier, monospace">       MainApp
        = TutorialWindow()</font><br>
      <font size="-1" face="Courier New, Courier, monospace">      
        MainApp.show()</font><br>
      <br>
      <font size="-1" face="Courier New, Courier, monospace">      
        sysExit(MainEvntThred.exec_())</font><br>
      <br>
    </p>
    <div>On 10/12/2019 10:02 AM, tanya
      tanyaradzwa wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="auto">
        <div dir="auto">Hello everyone,</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Referring to the assignment question l asked for
          your assistance, please find my code herein, and attached is
          the output on my side. Thank you. Tanya</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">import sys</div>
        <div dir="auto">from pprint import pprint</div>
        <div dir="auto">from PyQt5.QtWidgets import QWidget,
          QPushButton, QInputDialog, QLineEdit, QApplication</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">class TutorialWindow(QWidget):</div>
        <div dir="auto">      def __init(self):</div>
        <div dir="auto">            super().__init__()</div>
        <div dir="auto">            self.btn = QPushButton(&#39;Open&#39;, \
self)</div>  <div dir="auto">            self.btn.move(0, 20)</div>
        <div dir="auto">            self.btn.clicked.connect(self.showDialog)</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">            self.text_name = QLineEdit(self)</div>
        <div dir="auto">            self.text_name.move(100, 22)</div>
        <div dir="auto">            self.text_name.setPlaceholderText(&quot;Enter
          your name:&quot;)</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">            self.Geometry(300, 300, 290, 140)</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">            def showDialog(self):</div>
        <div dir="auto">                  text, result =
          QInputDialog.getText(self, &#39;Input Dialog&#39;, &#39;Enter your \
name:&#39;)</div>  <div dir="auto">                  if result ==True:</div>
        <div dir="auto">                        \
self.text_name.setText(str(text))</div>  <div dir="auto"><br>
        </div>
        <div dir="auto">if __name__ == &#39;__main__&#39;:</div>
        <div dir="auto">      app = QApplication(sys.argv)</div>
        <div dir="auto">      pprint(&quot;input parameters   = &quot; +
          str(sys.argv))</div>
        <div dir="auto">      tutorial_window = TutorialWindow()</div>
        <div dir="auto">      tutorial_window.show()</div>
        <div dir="auto">      sys.exit(app.exec_())</div>
        <div dir="auto"><br style="font-family:sans-serif;font-size:12.8px">
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Oct 4, 2019 14:33, &quot;tanya
          tanyaradzwa&quot; &lt;<a href="mailto:tanyatanyaradzwa460@gmail.com" \
target="_blank">tanyatanyaradzwa460@gmail.com</a>&gt;  wrote:<br type="attribution">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">  <div dir="auto">Hi \
Florian,  <div dir="auto"><br>
              </div>
              <div dir="auto">Thank you for your response.</div>
              <div dir="auto"><br>
              </div>
              <div dir="auto">I will send to you my code and the output
                on my side.</div>
            </div>
            <div class="gmail_extra"><br>
              <div class="gmail_quote">On Oct 4, 2019 09:56, &quot;Florian
                Bruhin&quot; &lt;<a href="mailto:me@the-compiler.org" \
target="_blank">me@the-compiler.org</a>&gt;  wrote:<br type="attribution">
                <blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey  Tanya,<br>
                  <br>
                  On Fri, Oct 04, 2019 at 08:50:50AM +0200, tanya
                  tanyaradzwa wrote:<br>
                  &gt; I am struggling with a school assignment. I have
                  researched all places<br>
                  &gt; online, but l am failing to bring it all
                  together. Please assist me.<br>
                  &gt; <br>
                  &gt; Question:<br>
                  &gt; <br>
                  &gt; Create an application using PyQt. The user is
                  prompted for the name of an<br>
                  &gt; animal rescue service. This must be displayed in
                  the UI in capital letters.<br>
                  &gt; The user is then required to enter a character
                  (letter). This must also be<br>
                  &gt; displayed on the UI in capital letters. The
                  application<br>
                  &gt; must read the name of the animal rescue service
                  as well as the character<br>
                  &gt; and then count the number of occurrences of the
                  character in the animal<br>
                  &gt; rescue service name. The count must be displayed.<br>
                  &gt; <br>
                  &gt; Also required:<br>
                  &gt; <br>
                  &gt; Error message for incorrect input from user (e.g.
                  no name of animal rescue<br>
                  &gt; service).<br>
                  &gt; Error message of character not found or the
                  character is blank!<br>
                  &gt; <br>
                  &gt; May you please assist. Thank you.<br>
                  <br>
                  If you have some specific issues, people here would
                  likely be happy to help.<br>
                  What do you have so far and where do you run into
                  issues?<br>
                  <br>
                  This pretty much boils down to &quot;please do my homework
                  for me&quot;, which at least<br>
                  I&#39;m not going to do.<br>
                  <br>
                  Florian<br>
                  <br>
                  -- <br>
                  <a href="https://www.qutebrowser.org" rel="noreferrer" \
                target="_blank">https://www.qutebrowser.org</a>
                  | <a href="mailto:me@the-compiler.org" \
target="_blank">me@the-compiler.org</a>  (Mail/XMPP)<br>
                       GPG: 916E B0C8 FD55 A072 | <a \
href="https://the-compiler.org/pubkey.asc" rel="noreferrer" \
                target="_blank">https://the-compiler.org/pubkey.asc</a><br>
                                I love long mails! | <a \
href="https://email.is-not-s.ms/" rel="noreferrer" \
target="_blank">https://email.is-not-s.ms/</a><br>  </blockquote>
              </div>
            </div>
          </blockquote>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a> <a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a> </pre>
    </blockquote>
  </div>

</blockquote></div>


["Dennis_Code_Output.PNG" (image/png)]
[Attachment #7 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic