Question

Question 3 [10] Create an application using PyQt. The user is prompted for the name of...

Question 3 [10]
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.
Required:
 Screenshot of the Animalxxxxxxxx.py program.
 Ensure that the screenshot shows your file name that includes your student number!
 Screenshot of output.
 Screen shot of the object inspector (all components named).
 Code: Input.
 Code: Result.
 Comments (at least 3)
 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!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Code:

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget,QLineEdit,QInputDialog,QMessageBox
from PyQt5.QtCore import QSize

def getText(self,prompt):
text, okPressed = QInputDialog.getText(self, "Get text",prompt+":", QLineEdit.Normal, "")
if okPressed and text != '':
return text
else:
QMessageBox.about(self, "Error", "Input should not be empty")
exit()
  
class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)

self.setMinimumSize(QSize(200, 200))
self.setWindowTitle("Animal Rescue Service")
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)   

gridLayout = QGridLayout(self)   
centralWidget.setLayout(gridLayout)
name=getText(self,"Please give animal rescue service name")
name=name.upper()
title = QLabel(name, self)
title.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(title, 0, 0)
char=getText(self,"Please give character to count")
occurence = name.lower().count(char)
if occurence==0:
QMessageBox.about(self, "Error", "Character not found")
else:
charInp = QLabel("Total occurence :"+str(occurence), self)
charInp.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(charInp, 1, 0)

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
sys.exit( app.exec_() )

Program screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
Question 3 [10] Create an application using PyQt. The user is prompted for the name of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks...

    Create a Console application for a library and name it FineForOverdueBooks. The Main( ) method asks the user to input the number of books that are overdue and the number of days they are overdue. Pass those values to a method that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day. Grading criteria 1. Create a Console...

  • Weather Program Create an application to interacts with a web service in order to obtain data....

    Weather Program Create an application to interacts with a web service in order to obtain data. Program must prompt the user for their city or zip code and request weather forecast data from OpenWeatherMap (https://openweathermap.org). Program must display the weather information in a READABLE format to the user. Requirements: Create a header for your program just as you have in the past. Create a Python Application which asks the user for their zip code or city. Use the zip code...

  • For this question you will need to complete the methods to create a JavaFX GUI application...

    For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...

  • Java programming for ticket price calculator.  It should ask the user if they would like to process...

    Java programming for ticket price calculator.  It should ask the user if they would like to process another ticket order. They should indicate their selection with a Y or N. If they indicate yes, then it should repeat the entire program with the exception of the welcome screen. If they indicate no, it should show the final thank you message and end the program. If they indicate an invalid answer, it should display an error and re-prompt them for a Y...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • I) will create a rudimentary (and highly insecure) database for the storage of only the user...

    I) will create a rudimentary (and highly insecure) database for the storage of only the user generated identities. This program will have the following behaviors: (line break, 11 pt) ) - Prior to prompting for a new username, the existing list of usernames should be read and loaded to an array. 1 ) Read the list from "users.txt", a prompt is not necessary. Do not change this data file name "users.txt". 2 ) The existing list of usernames should be...

  • Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input...

    Write a Java program called Flying.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records. A record in this file is a single line of text in the following format: Num of passengers^range^name^manufacturer^model where: Num of passengers is the total number of people in the plane. This represents an integer number, but remember that it is still part of the String so...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT