
- 23rd Jul 2024
- 17:46 pm
In this project, you are required to use your knowledge of Python to design an application of your choice with a graphical user interface and include some audio. The application should serve a purpose. It could be a game or data calculation/converter. You will need a welcome page with an introduction/instruction on how to use the program and logical navigation for the user to select their options. The criteria of this project is not restrictive to allow you to explore and experiment with Python and designing a GUI. However there has to be an objective for the program and how it should be used.
Free Assignment Solution - Designing a Purposeful Python Application with GUI and Audio
import random
from playsound import playsound
# import tkinter module
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
worldList = []
characterList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
characterButton = []
chance = 6
wordToGuess = ""
wordTemp = ""
def readWordList():
try:
f = open("words.txt")
l = f.readlines()
for i in l:
i = i.replace("\n","")
i = i.upper()
worldList.append(i)
f.close()
except Exception as ex:
print(ex)
print("Can't continue with the program beacuse wno word is present")
def checkWinLose():
global chance,wordToGuess,wordTemp
if '-' not in wordTemp:
messagebox.showinfo("showinfo", "Congratulations, You Won!!!")
reset()
if chance <= 0:
messagebox.showinfo("showinfo", "You Lose, Try again!!!")
reset()
def characterClick(char):
global chance,wordToGuess,wordTemp
playsound(char+".mp3")
for i in range(len(characterButton)):
if characterButton[i]['text'] == char:
characterButton[i].config(state="disabled")
if char in wordToGuess:
temp = ""
for i in range(len(wordToGuess)):
if wordToGuess[i] == char:
temp += char
else:
temp += wordTemp[i]
wordTemp = temp
wordlabel['text'] = wordTemp
else:
chance -= 1
chanceLabel['text'] = 'Number Chance left : ' + str(chance)
break
checkWinLose()
def reset():
global chance,wordToGuess,wordTemp
for i in range(len(characterButton)):
characterButton[i].config(state="normal")
chance = 6
wordToGuess = random.choice(worldList)
wordTemp = ""
for i in wordToGuess:
wordTemp += "-"
chanceLabel['text'] = 'Number Chance left : ' + str(chance)
wordlabel['text'] = wordTemp
if __name__ == "__main__":
readWordList()
if len(worldList) != 0:
wordToGuess = random.choice(worldList)
for i in wordToGuess:
wordTemp += "-"
win = Tk()
win.title("Hangman")
new_btn = Button(win,text = "New Game", command = reset)
exit_btn = Button(win,text = "Exit",command = win.destroy)
Description = Label(win, text = 'Hangman is a popular word guessing game where the player attempts to build a missing word by guessing one letter at a time. \nAfter a certain number of incorrect guesses, the game ends and the player loses. The game also ends if the player correctly identifies all the letters of the missing word.\n', font=('calibre',10, 'bold'))
chanceLabel = Label(win, text = 'Number Chance left : ' + str(chance), font=('calibre',10, 'bold'))
wordlabel = Label(win, text = wordTemp, font=('calibre',30, 'bold'))
for j in range(26):
btn = Button(win, text = characterList[j] ,command=lambda char = characterList[j]: characterClick(char))
if(j<=12):
btn.grid(row=5, column=j,padx = 6,pady = 4)
else:
btn.grid(row=6, column=j - 13,padx = 6,pady = 4)
characterButton.append(btn)
new_btn.grid(row = 0,column = 0,padx = 6,pady = 4)
exit_btn.grid(row = 0,column = 12,padx = 6,pady = 4)
Description.grid(row = 1,columnspan = 13,column = 0,padx =6,pady = 4)
chanceLabel.grid(row = 2,columnspan = 13,column = 0,padx =6,pady = 4)
wordlabel.grid(row = 3,columnspan = 13,column = 0,padx =6,pady = 4)
win.mainloop()#start the loop
Get the best Designing a Purposeful Python Application with GUI and Audio assignment help and tutoring services from our experts now!
Please note that this is a sample assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog above.
About The Author - Alex Gen
Alex Gen is a Python programming enthusiast with a knack for creating interactive and user-friendly applications. With experience in developing graphical user interfaces and incorporating audio features, Alex aims to design purposeful and engaging software solutions. His projects often blend creativity with technical proficiency, making them both functional and enjoyable.