Skip to content

Commit 9ab623b

Browse files
committed
Sorting hat game added
1 parent 25e2e90 commit 9ab623b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Diff for: PyGamesScripts/sorting hat game/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h3>Sorting Hat Game</h3>
2+
<hr>
3+
<h4>Built With</h4>
4+
<hr>
5+
<b>1.Python Tkinter</b>
6+
<b>2.Library used</b>
7+
tkinter- TKINTER is the standard GUI library used to provide fast and easy way to create GUI applications.<br>
8+
random- RANDOM Module is a built-in module which is used to give random numbers or choices by providing a set of methods.<br>
9+
10+
<h4>Aim</h4>
11+
It's aim is to assign a house name to the user when he/she clicks the button.
12+
<br>
13+
14+
<h4>Workflow of script</h4>
15+
<hr>
16+
Step 1: Import all the packages listed above.
17+
Step 2: Then a list consisting of house names is created.
18+
Step 3: Function "pickHouse" is defined to randomly select a house for the user.
19+
Step 4: Then main window is created with a title and size. Label and button is added to the window.
20+
Step 5: When we run the program, tkinter window appears with a label and a button "Choose your house".When the button is clicked , the house name which is assigned to you is displayed.
21+
22+
<h4>Output</h4>
23+
<hr>
24+
<b>Output Screenshot</b> <br>
25+
PyGamesScripts\sorting hat game\Images\initial_img.png<br>
26+
PyGamesScripts\sorting hat game\Images\first_output.png<br>
27+
PyGamesScripts\sorting hat game\Images\second_output.png<br>
28+
29+
<h4>Author</h4>
30+
Kamakshi Singh
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from tkinter import *
2+
import random
3+
4+
houses = ["Slytherin", "Gryffindor", "Hufflepuff", "Ravenclaw"] #list of houses
5+
6+
def pickHouse():#funcion to pick a house randomly
7+
hat.configure(text=(random.choice(houses)))
8+
9+
root = Tk() #initializes a blank 'root' window
10+
root.title("Sorting hat Game") #sets the title of window
11+
root.geometry("700x100") #sets the dimensions of window
12+
13+
#creates a label 'hat'
14+
hat = Label(root,text="This game selects a house for you. So click on the button",bg="purple",fg="yellow",font=("Calibri",18,"bold"))
15+
hat.pack() #adds 'hat' label onto 'root' window
16+
17+
#creates a button
18+
button = Button(root, text="Choose a House" , bd='5', bg="yellow", fg="red", font="andalus", activebackground="#34A2FE", activeforeground="black", justify="left", highlightcolor="purple", relief="groove", command=pickHouse)
19+
button.pack()#adds a button named 'Choose a House' on 'root' window
20+
21+
root.mainloop() #holds the window

0 commit comments

Comments
 (0)