Python tkinter Doubeling复选框

时间:2019-03-15 01:31:54

标签: python tkinter

我目前正在为学校项目在python内开发合成器,目前遇到了一个非常麻烦的问题。当弹奏音符时,音序器内的音高达到最高时,我有一个Checkboxes标记。我的问题是,每当我在合成器中打开两个振荡器并在复选框中放入“值”时,这些复选框会在多个窗口中复制其值,但不要针对实际序列执行此操作,因为我有两个具有正确值的列表,但这些值无法在窗口内正确显示。

要复制该问题,请单击“新振荡器”,然后单击“琶音”,再次执行此操作,然后单击琶音器Windows上的任何复选框。

我知道这可能令人困惑,但是我将在底部链接完整的代码,以便您可以尝试一下,并且可能知道我的尾巴。

该问题发生在“琶音”类中

import numpy                                # used for Waveform Calculation
from functools import partial               # used for Command Combining
from tkinter import *                       # used for GUI
from tkinter import ttk                     # used for GUI
from tkinter import filedialog              # used for GUI

np = numpy                      # Simplifying Libraries
tk = ttk                        # Simplifying Libraries
fd = filedialog                 # Simplifying Libraries

root = Tk()

#StartupFunction
def StartUp():
    print("")
    print("Starting Startup") 
    app = App(root)                 # Initializing GUI

    print("Finished Startup")
    main()
    ("Exiting Startup")

#Main Program Function
def main():
    print("Executing Main")
    root.mainloop()
    print("Finished Main")
    return 0

class Oscillator():
    pass

class App(tk.Frame):
    OscillatorWindowList = []
    OscillatorList = []
    SoundInputArrayList = []
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        root.title("PySynth")
        root.geometry("984x300")
        root.resizable(False, True)
        root.maxsize(984,720)
        btnNewOscillator = Button(root,text="New Oscillator",command=self.NewOscillator,relief=RIDGE,bg="#2d2d2d",fg="white")
        btnNewOscillator.place(x = 8, y = 8+128)

    def NewOscillator(self):
        print("AddingOscillator")
        self.OscillatorList.append(Oscillator())
        self.SoundInputArrayList.append(SoundInputArray(root,len(self.OscillatorList)-1,len(self.OscillatorList)-1))
        print(self.OscillatorList)
        self.OscillatorWindowList.append(OscillatorGUI(root,self.OscillatorList[len(self.OscillatorList)-1],len(self.OscillatorList)))

    def EXIT(self):
        root.destroy()

#$SoundInputArray
class SoundInputArray():
    actv = []
    CheckbuttonList = []
    CheckButtonFreq = []
    i=0
    ButtonCount = 32
    VolumeSlider = None
    btnArpeggio = None
    Arpeggio = None
    hasArpeggio = False
    LFO = None
    ArpeggioList = [(0,0)]

    def __init__(self,master,oscillatorCount,number):
        btnArpeggio = Button(master,text="Arpeggio",command=self.OpenArpeggio,relief=RIDGE,bg="#2d2d2d",fg="white")
        btnArpeggio.place(x = 8, y = (1+oscillatorCount)*48 +128 )

    def OpenArpeggio(self):
        if self.Arpeggio == None:
            self.Arpeggio = Arpeggio()

    def GetArpeggio(self):
        return self.Arpeggio

#$Arpeggio
class Arpeggio():
    SoundValueList = None

    def __init__(self):
        GUI = Toplevel(root)
        GUI.title("Arpeggio")
        GUI.geometry("480x320")
        GUI.resizable(False, False)
        GUI.configure(bg="#171717")
        self.SoundValueList = np.arange(0,16)
        self.DrawUI(GUI)
        self.ClearList()

    def DrawUI(self,frame):
        Button(frame,text="display", command= self.PrintSound, width=11,bg="#171717",).place(x = 4, y = 4)
        Button(frame,text="empty", command= self.ClearList).place(x = 96, y = 4)
        y = 1
        x = 1
        checkbuttonList = []
        for y in range(1,13):
            for x in range(0,16):
                updatecommand = partial(self.UpdateList,x,y)
                checkbuttonList.append(Checkbutton(frame, variable=self.SoundValueList[x], onvalue=y, offvalue=0,command = updatecommand))
                checkbuttonList[len(checkbuttonList)-1].place(x = x*24 + 96, y= y*24 + 8)
    def ClearList(self):
        for i in range(0,16):
            self.SoundValueList[i] = 0
    def UpdateList(self,x,value):
        if (self.SoundValueList[x] == value):
            self.SoundValueList[x] = 0
        else:
            self.SoundValueList[x] = value
        self.PrintSound()
    def PrintSound(self):
        print(self.SoundValueList)
    def GetList(self):
        print(self.SoundValueList)
        return self.SoundValueList

StartUp() # Initiate Programm

0 个答案:

没有答案