Python Tkinter错误:';非类型对象没有属性寄存器';

Python Tkinter错误:';非类型对象没有属性寄存器';,python,matplotlib,tkinter,ttk,tkinter-canvas,Python,Matplotlib,Tkinter,Ttk,Tkinter Canvas,我正在使用PythonX,Y(2.7.10)中的Tkinter和Matplotlib创建一个程序,用户可以在其中输入粒子的一些属性,并绘制一个表示其轨迹、距离等的二次图。然而,我无法对输入框进行看似简单的验证,输入框只接受数字。下面的代码片段是我在网上看到的验证的原始版本,但我无法让它在我的程序中工作。在工作片段下面是我尝试将其集成到窗口中的程序中,用户可以在其中添加新粒子。我会把整个(不完整的)程序放在底部,以防有帮助。如果你能想出任何其他的方法来验证,即使是非交互的,这将是非常受欢迎的。谢谢

我正在使用PythonX,Y(2.7.10)中的Tkinter和Matplotlib创建一个程序,用户可以在其中输入粒子的一些属性,并绘制一个表示其轨迹、距离等的二次图。然而,我无法对输入框进行看似简单的验证,输入框只接受数字。下面的代码片段是我在网上看到的验证的原始版本,但我无法让它在我的程序中工作。在工作片段下面是我尝试将其集成到窗口中的程序中,用户可以在其中添加新粒子。我会把整个(不完整的)程序放在底部,以防有帮助。如果你能想出任何其他的方法来验证,即使是非交互的,这将是非常受欢迎的。谢谢

工作原始代码片段:

from tkinter import *

root = Tk()

def testVal(inStr,i,acttyp):
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

entry = Entry(root, validate="key")
entry['validatecommand'] = (entry.register(testVal),'%P','%i','%d')
entry.pack()

root.mainloop()
def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)
from Tkinter import *
from ttk import *
from decimal import *
#global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
global inStr,i,acttyp
S=0.0
U=0.0
V=0.0
A=0.0
T=0.0
#SInput=()
#UInput=()
#VInput=()
#AInput=()
#TInput=()

class MainMenu(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)   

        self.parent = parent
        self.initUI()


    def initUI(self):

        self.parent.title("MechSim 0.2")
        self.style = Style()
        self.style.theme_use("clam")

        self.pack(fill=BOTH, expand=True)

        StartButton = Button(self, text="New Simulation", command=create_window).place(x=50, y=60)
        ExampleButton = Button(self, text="Example Simulation", command=create_window).place(x=50, y=110)
        ExitButton = Button(self, text="Exit MechSim", command=self.end).place(x=50, y=160)
        Title = Label(self, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=300, y=50)

    def end(self):
        quit()

def create_window():
    global canvas
    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib.figure import Figure
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.backend_bases import key_press_handler

    mainwind = Toplevel()
    mainwind.geometry("800x500+300+300")
    mainwind.wm_title("MechSim Simulator")
    mainwind.wm_style = Style()
    mainwind.wm_style.theme_use("clam")
    Title = Label(mainwind, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=620, y=7)

    f = matplotlib.figure.Figure(figsize=(5, 4), dpi=100)
    a = f.add_subplot(111)
    t = arange(0.0, 3.0, 0.01)
    s = sin(2*pi*t)

    a.plot(t,s)
    a.set_xlabel('Horizontal Distance (Metres)')
    a.set_ylabel('Vertical Distance (Metres)')

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.set_xlim(0,1000)
    ax.set_ylim(0,1000)
    canvas = FigureCanvasTkAgg(f, master=mainwind)
    canvas.show()

    canvas.get_tk_widget().place(x=270, y=50)
    f.subplots_adjust(left=0.16, bottom=0.14)

    NewPartButton = Button(mainwind, text ="Add New Particle", command=AddNewPart).place(x=50,y=50)

    toolbar = NavigationToolbar2TkAgg(canvas,mainwind)
    toolbar.update()

def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True


def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)

#def CheckSInp():
    #S=SInput
    #print S

    #SInput = SInp.get()
    #try:
        #Decimal(SInput)
    #xcept InvalidOperation:
        #SInput.set("Enter a number")
    #return SInput, SInp

def main():

    root = Tk()
    root.geometry("500x300+300+300")
    app = MainMenu(root)
    root.mainloop()

if __name__ == '__main__':
    main()  
我的程序中的非工作版本:

from tkinter import *

root = Tk()

def testVal(inStr,i,acttyp):
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

entry = Entry(root, validate="key")
entry['validatecommand'] = (entry.register(testVal),'%P','%i','%d')
entry.pack()

root.mainloop()
def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)
from Tkinter import *
from ttk import *
from decimal import *
#global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
global inStr,i,acttyp
S=0.0
U=0.0
V=0.0
A=0.0
T=0.0
#SInput=()
#UInput=()
#VInput=()
#AInput=()
#TInput=()

class MainMenu(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)   

        self.parent = parent
        self.initUI()


    def initUI(self):

        self.parent.title("MechSim 0.2")
        self.style = Style()
        self.style.theme_use("clam")

        self.pack(fill=BOTH, expand=True)

        StartButton = Button(self, text="New Simulation", command=create_window).place(x=50, y=60)
        ExampleButton = Button(self, text="Example Simulation", command=create_window).place(x=50, y=110)
        ExitButton = Button(self, text="Exit MechSim", command=self.end).place(x=50, y=160)
        Title = Label(self, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=300, y=50)

    def end(self):
        quit()

def create_window():
    global canvas
    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib.figure import Figure
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.backend_bases import key_press_handler

    mainwind = Toplevel()
    mainwind.geometry("800x500+300+300")
    mainwind.wm_title("MechSim Simulator")
    mainwind.wm_style = Style()
    mainwind.wm_style.theme_use("clam")
    Title = Label(mainwind, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=620, y=7)

    f = matplotlib.figure.Figure(figsize=(5, 4), dpi=100)
    a = f.add_subplot(111)
    t = arange(0.0, 3.0, 0.01)
    s = sin(2*pi*t)

    a.plot(t,s)
    a.set_xlabel('Horizontal Distance (Metres)')
    a.set_ylabel('Vertical Distance (Metres)')

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.set_xlim(0,1000)
    ax.set_ylim(0,1000)
    canvas = FigureCanvasTkAgg(f, master=mainwind)
    canvas.show()

    canvas.get_tk_widget().place(x=270, y=50)
    f.subplots_adjust(left=0.16, bottom=0.14)

    NewPartButton = Button(mainwind, text ="Add New Particle", command=AddNewPart).place(x=50,y=50)

    toolbar = NavigationToolbar2TkAgg(canvas,mainwind)
    toolbar.update()

def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True


def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)

#def CheckSInp():
    #S=SInput
    #print S

    #SInput = SInp.get()
    #try:
        #Decimal(SInput)
    #xcept InvalidOperation:
        #SInput.set("Enter a number")
    #return SInput, SInp

def main():

    root = Tk()
    root.geometry("500x300+300+300")
    app = MainMenu(root)
    root.mainloop()

if __name__ == '__main__':
    main()  
完整(不完整)程序:

from tkinter import *

root = Tk()

def testVal(inStr,i,acttyp):
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

entry = Entry(root, validate="key")
entry['validatecommand'] = (entry.register(testVal),'%P','%i','%d')
entry.pack()

root.mainloop()
def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True

def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)
from Tkinter import *
from ttk import *
from decimal import *
#global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
global inStr,i,acttyp
S=0.0
U=0.0
V=0.0
A=0.0
T=0.0
#SInput=()
#UInput=()
#VInput=()
#AInput=()
#TInput=()

class MainMenu(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)   

        self.parent = parent
        self.initUI()


    def initUI(self):

        self.parent.title("MechSim 0.2")
        self.style = Style()
        self.style.theme_use("clam")

        self.pack(fill=BOTH, expand=True)

        StartButton = Button(self, text="New Simulation", command=create_window).place(x=50, y=60)
        ExampleButton = Button(self, text="Example Simulation", command=create_window).place(x=50, y=110)
        ExitButton = Button(self, text="Exit MechSim", command=self.end).place(x=50, y=160)
        Title = Label(self, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=300, y=50)

    def end(self):
        quit()

def create_window():
    global canvas
    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib.figure import Figure
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.backend_bases import key_press_handler

    mainwind = Toplevel()
    mainwind.geometry("800x500+300+300")
    mainwind.wm_title("MechSim Simulator")
    mainwind.wm_style = Style()
    mainwind.wm_style.theme_use("clam")
    Title = Label(mainwind, text="MechSim 0.2", foreground="blue", font=("helvetica", 20)).place(x=620, y=7)

    f = matplotlib.figure.Figure(figsize=(5, 4), dpi=100)
    a = f.add_subplot(111)
    t = arange(0.0, 3.0, 0.01)
    s = sin(2*pi*t)

    a.plot(t,s)
    a.set_xlabel('Horizontal Distance (Metres)')
    a.set_ylabel('Vertical Distance (Metres)')

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.set_xlim(0,1000)
    ax.set_ylim(0,1000)
    canvas = FigureCanvasTkAgg(f, master=mainwind)
    canvas.show()

    canvas.get_tk_widget().place(x=270, y=50)
    f.subplots_adjust(left=0.16, bottom=0.14)

    NewPartButton = Button(mainwind, text ="Add New Particle", command=AddNewPart).place(x=50,y=50)

    toolbar = NavigationToolbar2TkAgg(canvas,mainwind)
    toolbar.update()

def testVal():
    global inStr,i,acttyp
    ind=int(i)
    if acttyp == '1': #insert
        if not inStr[ind].isdigit():
            return False
    return True


def AddNewPart():
    #global S, U, V, A, T, SInput, UInput, VInput, AInput, TInput
    global inStr,i,acttyp
    #SInp=()
    #UInp=()
    #VInp=()
    #AInp=()
    #TInp=()

    NewPartWind=Toplevel()
    NewPartWind.geometry("400x200+300+300")
    NewPartWind.wm_title("New Particle")
    NewPartWind.wm_style = Style()
    NewPartWind.wm_style.theme_use("clam")

    SLab=Label(NewPartWind, text="Distance Travelled (S)", foreground="blue", font=("helvetica", 8)).place(x=10,y=30)
    ULab=Label(NewPartWind, text="Initial Velocity (U)", foreground="blue", font=("helvetica", 8)).place(x=10,y=60)
    VLab=Label(NewPartWind, text="Final Velocity (V)", foreground="blue", font=("helvetica", 8)).place(x=10,y=90)
    ALab=Label(NewPartWind, text="Acceleration (A)", foreground="blue", font=("helvetica", 8)).place(x=10,y=120)
    TLab=Label(NewPartWind, text="Time Taken (T)", foreground="blue", font=("helvetica", 8)).place(x=10,y=150)

    SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
    SInp['validatecommand'] = (SInp.register(testVal),'%P','%i','%d')
    UInp=Entry(NewPartWind, validate="key").place(x=140,y=60)
    UInp['validatecommand'] = (UInp.register(testVal),'%P','%i','%d')
    VInp=Entry(NewPartWind, validate="key").place(x=140,y=90)
    VInp['validatecommand'] = (VInp.register(testVal),'%P','%i','%d')
    AInp=Entry(NewPartWind, validate="key").place(x=140,y=120)
    AInp['validatecommand'] = (AInp.register(testVal),'%P','%i','%d')
    TInp=Entry(NewPartWind, validate="key").place(x=140,y=150)
    TInp['validatecommand'] = (TInp.register(testVal),'%P','%i','%d')

    SOk = Button(NewPartWind, text="Ok").place(x=290, y=25)
    UOk = Button(NewPartWind, text="Ok").place(x=290, y=55)
    VOk = Button(NewPartWind, text="Ok").place(x=290, y=85)
    AOk = Button(NewPartWind, text="Ok").place(x=290, y=115)
    TOk = Button(NewPartWind, text="Ok",).place(x=290, y=145)

#def CheckSInp():
    #S=SInput
    #print S

    #SInput = SInp.get()
    #try:
        #Decimal(SInput)
    #xcept InvalidOperation:
        #SInput.set("Enter a number")
    #return SInput, SInp

def main():

    root = Tk()
    root.geometry("500x300+300+300")
    app = MainMenu(root)
    root.mainloop()

if __name__ == '__main__':
    main()  

在第二个代码中,您有:

SInp=Entry(NewPartWind, validate="key").place(x=140,y=30)
您正在对新创建的条目调用
place()
方法,该条目返回
None
。你应该:

SInp=Entry(NewPartWind, validate="key")
SInp.place(x=140,y=30)
首先创建小部件,然后为所有条目和其他小部件(如按钮)放置它