Skip to content

Commit 25e2e90

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

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed
Loading
Loading
Loading
Lines changed: 30 additions & 0 deletions
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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h4>LIBRARIES USED</h4>
2+
Tkinter, random
3+
<h5>tkinter Module</h5>
4+
<p>
5+
TKINTER is the standard GUI library used to provide fast and easy way to create GUI applications.<br>
6+
>> Tkinter provides some widgets few of them are listed below<br>
7+
>LABEL- It creates a single line caption for the window.<br>
8+
>BUTTON- It is used to display buttons on the window.<br>
9+
>widgets.PACK() Method- It adds the widgets onto main window.<br>
10+
>window.MAINLOOP() Method- It tells Python to run event loop which means the window is displayed until an event occurs(i.e. we press any key).<br>
11+
</p>
12+
13+
<h5>Random Module</h5>
14+
<p>
15+
RANDOM Module is a built-in module which is used to give random numbers or choices by providing a set of methods.<br>
16+
>random.choice() method gives a random element from the given sequence.<br>
17+
</p>
Lines changed: 21 additions & 0 deletions
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)