0
0 Комментариев

Здравствуйте. Есть такой код, вроде пианино.

`

from tkinter import *
from PIL import Image, ImageTk
from pygame import mixer
import time
from collections import deque
 
root =Tk()
 
a = int(10)
 
global Mylist
Mylist = deque()
 
def plus():
 
    global a
    a = int(a)
    a += 30
 
    c.create_line(0,50,500+a*2,50,width=2,fill="black")
    c.create_line(0,70,500+a*2,70,width=2,fill="black")
    c.create_line(0,90,500+a*2,90,width=2,fill="black")
    c.create_line(0,110,500+a*2,110,width=2,fill="black")
    c.create_line(0,130,500+a*2,130,width=2,fill="black")
 
 
def do(event):
 
    c.create_image(0+a,140,image=DO)
    plus()
 
    mixer.init()
    mixer.music.load('1.mp3')
    mixer.music.play()
    time.sleep(0.5)
    mixer.music.stop()
 
 
    Mylist.append(do)
 
 
def re(event):
 
    c.create_image(0+a,130,image=RE)
    plus()
 
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(re)
 
def mi(event):
    c.create_image(0+a,125,image=RE)
    plus()
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(mi)
 
def fa(event):
    c.create_image(0+a,118,image=RE)
    plus()
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(fa)
 
def so(event):
    c.create_image(0+a,105,image=RE)
    plus()
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(so)
 
def lu(event):
    c.create_image(0+a,96,image=RE)
    plus()
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(lu)
 
def si(event):
    c.create_image(0+a,86,image=RE)
    plus()
    mixer.init()
    mixer.music.load('2.mp3')
    mixer.music.play()
    time.sleep(2)
    mixer.music.stop()
 
    Mylist.append(si)
 
def bu(event):
    root.destroy()
 
def play(event):
    for play_note in Mylist:
        play_note(event)
 
 
A = dict(do=do,re=re,mi=mi,fa=fa,so=so,lu=lu,si=si)
 
c = Canvas(width=500,height=300,bg="white",cursor="pencil")
 
c.create_line(0,50,500,50,width=2,fill="black")
c.create_line(0,70,500,70,width=2,fill="black")
c.create_line(0,90,500,90,width=2,fill="black")
c.create_line(0,110,500,110,width=2,fill="black")
c.create_line(0,130,500,130,width=2,fill="black")
 
pilImage = Image.open("notaall.png")
DO= ImageTk.PhotoImage(pilImage)
 
pillImageRe = Image.open('notaall.png')
RE = ImageTk.PhotoImage(pillImageRe)
 
scr = Scrollbar(root)
scr.config(command = c.xview,orient = HORIZONTAL )
 
 
but = Button(root,text='Press to destroy window')
but.place(x=0,y=0)
but2 = Button(root,text = 'Press to replay')
but2.place(x =200,y = 0)
but2.bind('<Button-1>',play)
but.bind('<Button-1>',bu)
 
root.bind('k',do)
root.bind('s',re)
root.bind('d',mi)
root.bind('f',fa)
root.bind('g',so)
root.bind('h',lu)
root.bind('j',si)
c.pack()
scr.pack()
 
root.mainloop()

введите сюда описание изображения

`

Как корректно исправить ошибку?


Добавить комментарий