<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" 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('Tutorial Window')</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('Open')</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("Enter your name:")</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, 'Input Dialog', 'Enter
your name:')</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('echo')</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__
== '__main__':</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('Command Line Arguements = ' + 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 class="moz-cite-prefix">On 10/12/2019 10:02 AM, tanya
tanyaradzwa wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CABO0HDFG-cd3DCKRYXq_GUfnagj7rCxV-enWe7C5bNfx+34mSg@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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('Open', self)</div>
<div dir="auto"> self.btn.move(0, 20)</div>
<div dir="auto"> self.btn.clicked.connect(self.<wbr>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.<wbr>setPlaceholderText("Enter
your name:")</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, 'Input Dialog', 'Enter your name:')</div>
<div dir="auto"> if result ==True:</div>
<div dir="auto"> self.text_name.setText(str(<wbr>text))</div>
<div dir="auto"><br>
</div>
<div dir="auto">if __name__ == '__main__':</div>
<div dir="auto"> app = QApplication(sys.argv)</div>
<div dir="auto"> pprint("input parameters = " +
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, "tanya
tanyaradzwa" <<a
href="mailto:tanyatanyaradzwa460@gmail.com"
moz-do-not-send="true">tanyatanyaradzwa460@gmail.com</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;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, "Florian
Bruhin" <<a href="mailto:me@the-compiler.org"
target="_blank" moz-do-not-send="true">me@the-compiler.org</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hey
Tanya,<br>
<br>
On Fri, Oct 04, 2019 at 08:50:50AM +0200, tanya
tanyaradzwa wrote:<br>
> I am struggling with a school assignment. I have
researched all places<br>
> online, but l am failing to bring it all
together. Please assist me.<br>
> <br>
> Question:<br>
> <br>
> Create an application using PyQt. The user is
prompted for the name of an<br>
> animal rescue service. This must be displayed in
the UI in capital letters.<br>
> The user is then required to enter a character
(letter). This must also be<br>
> displayed on the UI in capital letters. The
application<br>
> must read the name of the animal rescue service
as well as the character<br>
> and then count the number of occurrences of the
character in the animal<br>
> rescue service name. The count must be displayed.<br>
> <br>
> Also required:<br>
> <br>
> Error message for incorrect input from user (e.g.
no name of animal rescue<br>
> service).<br>
> Error message of character not found or the
character is blank!<br>
> <br>
> 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 "please do my homework
for me", which at least<br>
I'm not going to do.<br>
<br>
Florian<br>
<br>
-- <br>
<a href="https://www.qutebrowser.org" rel="noreferrer"
target="_blank" moz-do-not-send="true">https://www.qutebrowser.org</a>
| <a href="mailto:me@the-compiler.org"
target="_blank" moz-do-not-send="true">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"
moz-do-not-send="true">https://the-compiler.org/pubke<wbr>y.asc</a><br>
I love long mails! | <a
href="https://email.is-not-s.ms/" rel="noreferrer"
target="_blank" moz-do-not-send="true">https://email.is-not-s.ms/</a><br>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
PyQt mailing list <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a>
</pre>
</blockquote>
</body>
</html>