Python 让“课堂”在tkinter发挥作用

Python 让“课堂”在tkinter发挥作用,python,class,object,tkinter,Python,Class,Object,Tkinter,我一直在想办法在Python Tkinter找一份课堂作业。 但是当用if name==main调用它时,如果你对这个问题有任何解决方案,我会非常感激。如果你有任何解决方案不涉及我使用的if语句,请告诉我 class Calculo: def _init_(self,parent): def calcular_moduloV1(self): if Vel_in_y.get()>0 and Angulo_desp.get():

我一直在想办法在Python Tkinter找一份课堂作业。 但是当用if name==main调用它时,如果你对这个问题有任何解决方案,我会非常感激。如果你有任何解决方案不涉及我使用的if语句,请告诉我

class Calculo:
     def _init_(self,parent):

        def calcular_moduloV1(self):
                if Vel_in_y.get()>0 and Angulo_desp.get():
                    self.modulo = Vel_in_y.get()* math.sin(math.radians(Angulo_desp.get()))  
                    label = tkinter.Label(frame,text=self.modulo)
                    label.pack()
        def calcular_moduloV2(self):
            if Vel_in_x.get()>0 and Vel_in_y.get()>0 and self.modulo == 0:
                self.modulos = math.sqrt(Vel_in_x.get()**2+ Vel_in_y.get()**2)
                label = tkinter.Label(frame,text=self.modulos)
                label.pack()
        def calcular_anguloD(self):
            if Vel_in_y.get()>0 and Vel_in_x.get()>0:
                self.angulo = math.degrees(math.tanh(Vel_in_y.get()/Vel_in_x.get()))
                label = tkinter.Label(frame,text=self.angulo)
                label.pack()
        def calcular_Vel_in_y(self):
            if Angulo_desp.get()>0 and Velocidad_in.get()>0 and Vel_in_y.get()==0:
                self.Vel_y = Velocidad_in.get()*math.sin(math.radians(Angulo_desp.get()))
                label = tkinter.Label(frame,text=self.Vel_y)
                label.pack()
        def calcular_Vel_in_x(self):
            if Angulo_desp.get()>0 and Velocidad_in.get()>0 and Vel_in_x.get()==0:
                self.Vel_x= Velocidad_in.get()*math.cos(math.radians(Angulo_desp.get()))
                label = tkinter.Label(frame,text=self.Vel_x)
                label.pack()

        button = tkinter.Button(frame,text='respuesta' ,command = 
                                (self.calcular_moduloV1,self.calcular_moduloV2,self.calcular_anguloD,self.calcular_Vel_in_y,self.calcular_Vel_in_x))
        button.pack()
if _name_ == "_main_":
    window =tkinter.Tk()
    myapp = Calculo(window)
    window.mainloop()
这只是一段代码…如果你需要整个东西,请给我发一条消息,谢谢

评论很少

首先

定义初始自身,父级:

应该是

定义初始自我,父级:

第二,正如其他人指出的那样: _名称==\u主_

应该是

__名称\uuuu==\uuuuu main__

第三,。此按钮没有意义,尤其是命令:

    button = tkinter.Button(frame,text='respuesta' ,command = 
                     (self.calcular_moduloV1, self.calcular_moduloV2,self.calcular_anguloD, self.calcular_Vel_in_y,self.calcular_Vel_in_x))
button.pack()
你想在这里实现什么?框架也没有定义


第四,def calcular_moduleov1 self:在主体中有错误的缩进。

if\uuuuuuu name\uuuuuuu==\uuuuuu main\uuuu。两边都有双下划线运行该脚本时会出现什么错误?问题是即使我放置了双下划线,类也不会运行。是否确实在运算符的两边都放置了双下划线?如果只从该文件运行,则不需要if子句。你知道你为什么用这个短语吗?