Created
April 29, 2017 02:40
-
-
Save ItsBerry/de245ba70376cb07f4dbe2d25c223f5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageTk | |
import tkinter as tk | |
from random import randint | |
notes = ["C", "D", "E", "F", "G", "A", "B", "C", "D", "E", "F", "G"] | |
noteFiles = ["Notes\\middle_c.png", "Notes\\low_d.png", "Notes\\low_e.png", | |
"Notes\\low_f.jpg", "Notes\\low_g.png", "Notes\\a.jpg", | |
"Notes\\b.png", "Notes\\high_c.jpg", "Notes\\high_d.jpg", | |
"Notes\\high_e.png", "Notes\\high_f.jpg", "Notes\\high_g.png"] | |
root = tk.Tk() | |
canvas = tk.Canvas(root, width=950, height=700) | |
canvas.pack() | |
def client_exit(): | |
''' Quit Button ''' | |
exit() | |
def pickNote(value): | |
''' Changes noteChosen var to the note's button pressed ''' | |
global noteChosen | |
noteChosen = value | |
print(noteChosen) | |
# Creates button to exit the program | |
quitButton = tk.Button(text="Quit", command=client_exit) | |
quitButton.place(x=480, y=480) | |
# Creates buttons for various notes | |
aButton = tk.Button(text="A", command=lambda *args: pickNote("A")) | |
aButton.config(height=3, width=9) | |
aButton.place(x=190, y=400) | |
bButton = tk.Button(text="B", command=lambda *args: pickNote("B")) | |
bButton.config(height=3, width=9) | |
bButton.place(x=280, y=400) | |
cButton = tk.Button(text="C", command=lambda *args: pickNote("C")) | |
cButton.config(height=3, width=9) | |
cButton.place(x=370, y=400) | |
dButton = tk.Button(text="D", command=lambda *args: pickNote("D")) | |
dButton.config(height=3, width=9) | |
dButton.place(x=460, y=400) | |
eButton = tk.Button(text="E", command=lambda *args: pickNote("E")) | |
eButton.config(height=3, width=9) | |
eButton.place(x=550, y=400) | |
fButton = tk.Button(text="F", command=lambda *args: pickNote("F")) | |
fButton.config(height=3, width=9) | |
fButton.place(x=640, y=400) | |
gButton = tk.Button(text="G", command=lambda *args: pickNote("G")) | |
gButton.config(height=3, width=9) | |
gButton.place(x=730, y=400) | |
# Begin practice game | |
while True: | |
randomNote = randint(0, 11) | |
path = noteFiles[randomNote] | |
correctNote = notes[randomNote] | |
img = Image.open(path) | |
tk_img = ImageTk.PhotoImage(img) | |
canvas.create_image(505, 200, image=tk_img) | |
root.mainloop() | |
if correctNote == noteChosen: | |
''' User got last note right ''' | |
canvas.delete("all") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment