Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将两个函数的值相加?(2.0)_Python_Inheritance_Tkinter - Fatal编程技术网

Python 如何将两个函数的值相加?(2.0)

Python 如何将两个函数的值相加?(2.0),python,inheritance,tkinter,Python,Inheritance,Tkinter,正如我昨天承诺的,真正的代码来了 我将编写一个程序,用于定义房间中的混响时间。解释整个项目,花了太多时间。我尝试了建议的方法,但我做错了 在第一页中,有不同声音频率下材料的所有吸收度,在第二页中,用户必须输入面积(平方米)并选择材料。按下OK按钮后,函数getBottomChoice和getWallChoice将PageOne中的材料值乘以用户输入,以获得吸收面积。但不幸的是,它不起作用。我如何打印所选材料的新值吸附面积,仅用于签入?最后但并非最不重要的是,我如何总结所选材料的abs面积并打印出

正如我昨天承诺的,真正的代码来了

我将编写一个程序,用于定义房间中的混响时间。解释整个项目,花了太多时间。我尝试了建议的方法,但我做错了

在第一页中,有不同声音频率下材料的所有吸收度,在第二页中,用户必须输入面积(平方米)并选择材料。按下OK按钮后,函数getBottomChoice和getWallChoice将PageOne中的材料值乘以用户输入,以获得吸收面积。但不幸的是,它不起作用。我如何打印所选材料的新值吸附面积,仅用于签入?最后但并非最不重要的是,我如何总结所选材料的abs面积并打印出来,按频率列出?提前谢谢

import tkinter as tk
from tkinter import ttk
from tkinter import *
import math
LARGE_FONT = ("Verdana", 12)



class ReverberationTime(tk.Tk):


    def __init__(self,*args,**kwargs):


        tk.Tk.__init__(self, *args, **kwargs)

        tk.Tk.wm_title(self, "reverberation time")
        tk.Tk.iconbitmap(self,"C:/Users/PC/Desktop/Icons/speaker.ico")

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)    
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, PageOne, PageTwo, PageThree):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self,cont):

        frame = self.frames[cont]

        frame.tkraise()



class Pages:
    p = 0
    z = 1
    abs_flä = 1

    def __init__(self):

        self.parkett_125 = 0.04
        self.parkett_250 = 0.04
        self.parkett_500 = 0.05
        self.parkett_1000 = 0.06
        self.parkett_2000 = 0.06
        self.parkett_4000 = 0.06

        self.linoleum_125 = 0.02
        self.linoleum_250 = 0.02
        self.linoleum_500 = 0.03
        self.linoleum_1000 = 0.03
        self.linoleum_2000 = 0.04
        self.linoleum_4000 = 0.04

        self.pvc_125 = 0.02
        self.pvc_250 = 0.02
        self.pvc_500 = 0.01
        self.pvc_1000 = 0.03
        self.pvc_2000 = 0.05
        self.pvc_4000 = 0.05

        self.tapete_125 = 0.02
        self.tapete_250 = 0.03
        self.tapete_500 = 0.04
        self.tapete_1000 = 0.05
        self.tapete_2000 = 0.07
        self.tapete_4000 = 0.08

        self.glattputz_125 = 0.02
        self.glattputz_250 = 0.02
        self.glattputz_500 = 0.03
        self.glattputz_1000 = 0.03
        self.glattputz_2000 = 0.04
        self.glattputz_4000 = 0.06

        self.mauerziegelwand_125 = 0.02
        self.mauerziegelwand_250 = 0.02
        self.mauerziegelwand_500 = 0.03
        self.mauerziegelwand_1000 = 0.04
        self.mauerziegelwand_2000 = 0.05
        self.mauerziegelwand_4000 = 0.06

    def bottoms(self,parkett_125,parkett_250,parkett_500,parkett_1000,
                parkett_2000,parkett_4000,linoleum_125,linoleum_250,linoleum_500,
                linoleum_1000,linoleum_2000,linoleum_4000,pvc_125,
                pvc_250,pvc_500,pvc_1000,pvc_2000,pvc_4000):

        self.parkett_125 = parkett_125
        self.parkett_250 = parkett_250
        self.parkett_500 = parkett_500
        self.parkett_1000 = parkett_1000
        self.parkett_2000 = parkett_2000
        self.parkett_4000 = parkett_4000

        self.linoleum_125 = linoleum_125
        self.linoleum_250 = linoleum_250
        self.linoleum_500 = linoleum_500
        self.linoleum_1000 = linoleum_1000
        self.linoleum_2000 = linoleum_2000
        self.linoleum_4000 = linoleum_4000

        self.pvc_125 = pvc_125
        self.pvc_250 = pvc_250
        self.pvc_500 = pvc_500
        self.pvc_1000 = pvc_1000
        self.pvc_2000 = pvc_2000
        self.pvc_4000 = pvc_4000  

    def walls(self,tapete_125,tapete_250,tapete_500,tapete_1000,tapete_2000,tapete_4000,
              glattputz_125,glattputz_250,glattputz_500,glattputz_1000,glattputz_2000,glattputz_4000,
              mauerziegelwand_125,mauerziegelwand_250,mauerziegelwand_500,mauerziegelwand_1000,mauerziegelwand_2000,mauerziegelwand_4000):

        self.tapete_125 = tapete_125
        self.tapete_250 = tapete_250
        self.tapete_500 = tapete_500
        self.tapete_1000 = tapete_1000
        self.tapete_2000 = tapete_2000
        self.tapete_4000 = tapete_4000

        self.glattputz_125 = glattputz_125
        self.glattputz_250 = glattputz_250
        self.glattputz_500 = glattputz_500
        self.glattputz_1000 = glattputz_1000
        self.glattputz_2000 = glattputz_2000
        self.glattputz_4000 = glattputz_4000

        self.mauerziegelwand_125 = mauerziegelwand_125
        self.mauerziegelwand_250 = mauerziegelwand_250
        self.mauerziegelwand_500 = mauerziegelwand_500
        self.mauerziegelwand_1000 = mauerziegelwand_1000
        self.mauerziegelwand_2000 = mauerziegelwand_2000
        self.mauerziegelwand_4000 = mauerziegelwand_4000


class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)
        label = tk.Label(self, text="reverberation time", font=LARGE_FONT)
        label.pack(pady = 10, padx = 10)

        button = ttk.Button(self, text="welcome!", 
                            command=lambda: controller.show_frame(PageOne)).pack()


class PageOne(tk.Frame, Pages):


    def __init__(self, parent, controller):


        tk.Frame.__init__(self, parent)
        NORMAL_FONT=("Arial",11)

        title = tk.Label(self, text="Please enter the room dimensions.", font=LARGE_FONT)
        title.pack(pady = 10, padx = 10)

        frame = Frame(self)
        frame.pack(pady=20)

        self.lenght = StringVar()
        self.width = StringVar()
        self.height = StringVar()
        self.v = StringVar()

        dimensions = Frame(frame)
        dimensions.pack(side='left', pady=5)

        entryfields = Frame(frame)
        entryfields.pack(side='right', pady=5)

        lblLenght = Label(dimensions, text="lenght:", font=NORMAL_FONT)
        lblLenght.pack(pady=3)
        lblWidth = Label(dimensions, text="width:", font=NORMAL_FONT)
        lblWidth.pack(pady=4)
        lblHeight = Label(dimensions, text="height:", font=NORMAL_FONT)
        lblHeight.pack(pady=4)
        lblVolume = Label(dimensions, textvariable = self.v)
        lblVolume.pack()


        entLength = Entry(entryfields, textvariable = self.lenght)
        entLength.pack(pady=6)
        entWidth = Entry(entryfields, textvariable = self.width)
        entWidth.pack(pady=6)
        entHeight = Entry(entryfields, textvariable = self.height)
        entHeight.pack(pady=6)


        btncalculate = ttk.Button(self, text="calculate")
        btncalculate.pack()
        btncalculate.bind("<Button-1>", self.calculate)

        btnPageTwo = ttk.Button(self, text="Page 2", command=lambda: controller.show_frame(PageTwo))
        btnPageTwo.pack()

        btnStartPage = ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage))
        btnStartPage.pack()



    def calculate(self, carryout):
        try:
            l = float(self.lenght.get())
            b = float(self.width.get())
            h = float(self.height.get())
            m = l*b*h
            self.v.set("volume: % .2f m³" % m)
            Pages.p = m

        except ValueError:
            tk.messagebox.showinfo('No valid input.','Please enter only numbers!',icon = 'warning')


class PageTwo(tk.Frame, Pages):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        NORMAL_FONT=("Arial",11)

        title = tk.Label(self, text="Please select the bottom abilities.", font=LARGE_FONT)
        title.pack(pady = 10, padx = 10)

        self.bottomMaterial =StringVar()
        self.bottom = StringVar()

        self.wallMaterial =StringVar()
        self.wall = StringVar()

        frame = Frame(self)
        frame.pack(pady=20)

        dimensions = Frame(frame)
        dimensions.pack(side='left', pady=5)

        entBottom = Entry(dimensions, textvariable = self.bottom)
        entBottom.grid(pady = 5)
        self.cboBottomMaterial = ttk.Combobox(dimensions, textvariable = self.bottomMaterial, state = 'readonly',font = ('arial', 14, 'bold'), width = 19)
        self.cboBottomMaterial ['value'] = ('Parkett', 'Linoleum', 'PVC')
        self.cboBottomMaterial.current(0)
        self.cboBottomMaterial.grid()
        btnBottomChoice = ttk.Button(dimensions, text = "OK", command = self.getBottomChoice)
        btnBottomChoice.grid()

        entWall = Entry(dimensions, textvariable = self.wall)
        entWall.grid(pady = 5)
        self.cboWallMaterial = ttk.Combobox(dimensions, textvariable = self.wallMaterial, state = 'readonly',font = ('arial', 14, 'bold'), width = 19)
        self.cboWallMaterial ['value'] = ('Tapete', 'Glattputz', 'Mauerziegelwand')
        self.cboWallMaterial.current(0)
        self.cboWallMaterial.grid()
        btnWallChoice = ttk.Button(dimensions, text = "OK", command = self.getWallChoice)
        btnWallChoice.grid()

        btnsumAbsorptionArea = ttk.Button(self, text="sum")
        btnsumAbsorptionArea.pack()
        btnsumAbsorptionArea.bind("<Button-1>", self.sumAbsorptionArea)



        btnPageTwo = ttk.Button(self, text="Page 1", command=lambda: controller.show_frame(PageOne))
        btnPageTwo.pack()

        btnStartPage = ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage))
        btnStartPage.pack()

        btnStartPage = ttk.Button(self, text="Page 3", command=lambda: controller.show_frame(PageThree))
        btnStartPage.pack()

    def getBottomChoice(self):

            if self.cboBottomMaterial.get() == "Parkett":
                self.bottoms(
               self.parkett_125 * float(self.bottom.get()),
               self.parkett_250 * float(self.bottom.get()),
               self.parkett_500 * float(self.bottom.get()),
               self.parkett_1000 * float(self.bottom.get()),
               self.parkett_2000 * float(self.bottom.get()),
               self.parkett_4000 * float(self.bottom.get())
               )

            elif self.cboBottomMaterial.get() == "Linoleum":
                self.bottoms(
               self.linoleum_125 * float(self.bottom.get()),
               self.linoleum_250 * float(self.bottom.get()),
               self.linoleum_500 * float(self.bottom.get()),
               self.linoleum_1000 * float(self.bottom.get()),
               self.linoleum_2000 * float(self.bottom.get()),
               self.linoleum_4000 * float(self.bottom.get())
               )

            elif self.cboBottomMaterial.get() == "PVC":
               self.bottoms(
               self.pvc_250 * float(self.bottom.get()),
               self.pvc_500 * float(self.bottom.get()),
               self.pvc_1000 * float(self.bottom.get()),
               self.pvc_2000 * float(self.bottom.get()),
               self.pvc_4000 * float(self.bottom.get())
               )

            elif self.cboBottomMaterial.get() == "":
                messagebox.showinfo('No valid input.','Please select.',icon = 'warning')



    def getWallChoice(self):

            if self.cboWallMaterial.get() == "Tapete":
                self.walls(
               self.tapete_125 * float(self.wall.get()),
               self.tapete_250 * float(self.wall.get()),
               self.tapete_500 * float(self.wall.get()),
               self.tapete_1000 * float(self.wall.get()),
               self.tapete_2000 * float(self.wall.get()),
               self.tapete_4000 * float(self.wall.get())
               )

            elif self.cboWallMaterial.get() == "Glattputz":
                self.walls(
               self.glattputz_125 * float(self.wall.get()),
               self.glattputz_250 * float(self.wall.get()),
               self.glattputz_500 * float(self.wall.get()),
               self.glattputz_1000 * float(self.wall.get()),
               self.glattputz_2000 * float(self.wall.get()),
               self.glattputz_4000 * float(self.wall.get())
               )

            elif self.cboWallMaterial.get() == "Mauerziegelwand":
               self.walls(
               self.mauerziegelwand_250 * float(self.wall.get()),
               self.mauerziegelwand_500 * float(self.wall.get()),
               self.mauerziegelwand_1000 * float(self.wall.get()),
               self.mauerziegelwand_2000 * float(self.wall.get()),
               self.mauerziegelwand_4000 * float(self.wall.get())
               )

            elif self.cboWallMaterial.get() == "":
                messagebox.showinfo('No valid input.','Please select.',icon = 'warning')


    def sumAbsorptionArea(self,sum):

        sum = self.getBottomChoice + self.getWallChoice
        print (sum)


class PageThree(tk.Frame, Pages):


    def passvariable(self, var):
            self.s.set("volume: % .2f m³" % Pages.p)

    def absorptionsrate(self, var):
            self.abs_rate.set("volume: % .2f m³" % Pages.abs_flä)

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)

        frame = Frame(self)
        frame.pack(pady=20)

        result_var = StringVar()
        selected_var = StringVar()
        self.s = StringVar()
        items_for_listbox = ["Musik","Sprache","Vortrag","Spr.+Vor.","Sport"]
        self.abs_rate = StringVar()

        def select(event):

            a = mylistbox.get(ANCHOR)
            Pages.z = curselection(a) 
            selected_var.set(Pages.z)

        def curselection(a):

            if a=="Musik":
                T_soll_A1 = 0.45*math.log10(Pages.p)+0.07                
                return (T_soll_A1)

            elif a=="Sprache":
                T_soll_A2 = 0.37*math.log10(Pages.p)-0.14             
                return (T_soll_A2)

            elif a=="Vortrag":
                T_soll_A3 = 0.32*math.log10(Pages.p)-0.17               
                return (T_soll_A3)

            elif a=="Spr.+Vor.":    
                T_soll_A4 = 0.26*math.log10(Pages.p)-0.14           
                return (T_soll_A4)

            elif a=="Sport":    
                T_soll_A5 = 0.75*math.log10(Pages.p)-1              
                return (T_soll_A5)

        def calc():

                if mylistbox.get(ACTIVE):
                    Abs_Fl_ges = 0.163 * Pages.p / Pages.z
                    Absorber = Abs_Fl_ges - Pages.abs_flä
                    result_var.set(Absorber) 

                elif Pages.z == 0:
                    messagebox.showinfo("No selection")

        self.dimension = Frame(frame)
        self.dimension.pack(side='left', pady=5)

        lblPageTwo = tk.Label(self, text="Page 2", font=LARGE_FONT)
        lblPageTwo.pack(pady = 10, padx = 10)

        lblAbs_rate = tk.Label(self.dimension, textvariable = self.abs_rate)
        lblAbs_rate.pack()

        pasvar = tk.Label(self.dimension, textvariable = self.s)
        pasvar.pack()

        lblselection = tk.Label(self.dimension, textvariable=selected_var)
        lblselection.pack(expand=YES)
        selected_var.set("No selection")


        lblresult = Label(self.dimension, textvariable=result_var)
        lblresult.pack(expand=YES)
        result_var.set("No result")

        listbox_frame = Frame(self.dimension)
        listbox_frame.pack(expand=YES)

        mylistbox = Listbox(listbox_frame, height=5, width=10, font=('times',18))
        mylistbox.bind('<<ListboxSelect>>', select)
        mylistbox.grid(row=0, column=0)
        mylistbox.insert(END, *items_for_listbox)

        scroll = Scrollbar(listbox_frame, orient=VERTICAL) # the alignment of the scrollbar
        mylistbox["yscrollcommand"] = scroll.set # link the list with the scroll
        scroll["command"] = mylistbox.yview # link the scroll with the scroll
        scroll.grid(row=0, column=1, sticky=N+S) #sticky=N+S+E)

        btnAbsorber=Button(self.dimension, text="Fläche der Absorber", command=calc)
        btnAbsorber.pack(expand=YES)

        btnStartPage = ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage))
        btnStartPage.pack()

        btnPageOne = ttk.Button(self, text="Page 1", command=lambda: controller.show_frame(PageOne))
        btnPageOne.pack()

        btnPageTwo = ttk.Button(self, text="Page 2", command=lambda: controller.show_frame(PageTwo))
        btnPageTwo.pack()

        btnPassVariable = ttk.Button(self, text="pasvariable")
        btnPassVariable.pack()
        btnPassVariable.bind("<Button-1>", self.passvariable)

        btnAbs_rate = ttk.Button(self, text="pass absorption rate")
        btnAbs_rate.pack()
        btnAbs_rate.bind("<Button-1>", self.absorptionsrate)



app = ReverberationTime()
app.mainloop() ```

好了,我们的谈话结束了,在评论和一些关于事物如何联系的假设中,我重构了你的代码

让我知道如果有什么不工作,作为仔细检查

4缩进空格为标准。它有助于提高可读性,如果遵循标准,可以避免缩进不匹配等问题

确保您的示例中包含所有导入内容,因为这是一个重要的故障排除步骤,让我们知道可能需要哪些库来测试您的示例

我已经按照PEP8标准重构了您的代码。你有一个混合格式正在进行,没有什么是一致的

从多个类继承可能会很棘手,因此,请改为从框架继承,然后创建一个作为页面实例的类属性

从页面中的属性创建新值的函数的工作方式与预期不同。相反,您将希望对所有内容求和,然后返回该求和值

sumAbsorptionArea方法中的数学无法工作,因为您正在使用对方法的引用,而不是执行这些方法

出于某种原因,在按钮上混合使用命令和绑定,因此在某些函数/方法中必须有一个事件变量。相反,只需使用命令

就个人而言,您使用了很多行来定义属性。我会想办法缩短这个。最好是一个值列表或一个字典在这里工作得很好。不过你可以自己解决这个问题D

重构代码:

import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import math
LARGE_FONT = ("Verdana", 12)


class ReverberationTime(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        tk.Tk.wm_title(self, "reverberation time")
        # tk.Tk.iconbitmap(self, "C:/Users/PC/Desktop/Icons/speaker.ico")
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (StartPage, PageOne, PageTwo, PageThree):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")
        self.show_frame(StartPage)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()


class Pages:
    p, z, abs_flä = 0, 1, 1

    def __init__(self):
        self.parkett_125 = 0.04
        self.parkett_250 = 0.04
        self.parkett_500 = 0.05
        self.parkett_1000 = 0.06
        self.parkett_2000 = 0.06
        self.parkett_4000 = 0.06
        self.linoleum_125 = 0.02
        self.linoleum_250 = 0.02
        self.linoleum_500 = 0.03
        self.linoleum_1000 = 0.03
        self.linoleum_2000 = 0.04
        self.linoleum_4000 = 0.04
        self.pvc_125 = 0.02
        self.pvc_250 = 0.02
        self.pvc_500 = 0.01
        self.pvc_1000 = 0.03
        self.pvc_2000 = 0.05
        self.pvc_4000 = 0.05
        self.tapete_125 = 0.02
        self.tapete_250 = 0.03
        self.tapete_500 = 0.04
        self.tapete_1000 = 0.05
        self.tapete_2000 = 0.07
        self.tapete_4000 = 0.08
        self.glattputz_125 = 0.02
        self.glattputz_250 = 0.02
        self.glattputz_500 = 0.03
        self.glattputz_1000 = 0.03
        self.glattputz_2000 = 0.04
        self.glattputz_4000 = 0.06
        self.mauerziegelwand_125 = 0.02
        self.mauerziegelwand_250 = 0.02
        self.mauerziegelwand_500 = 0.03
        self.mauerziegelwand_1000 = 0.04
        self.mauerziegelwand_2000 = 0.05
        self.mauerziegelwand_4000 = 0.06


class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="reverberation time", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        button = ttk.Button(self, text="welcome!",
                           command=lambda: controller.show_frame(PageOne)).pack()


class PageOne(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        super(PageOne).__init__()
        self.Pages = Pages()
        normal_font = ("Arial", 11)
        tk.Label(self, text="Please enter the room dimensions.", font=LARGE_FONT).pack(pady=10, padx=10)
        frame = tk.Frame(self)
        frame.pack(pady=20)
        self.length = tk.StringVar()
        self.width = tk.StringVar()
        self.height = tk.StringVar()
        self.v = tk.StringVar()
        dimensions = tk.Frame(frame)
        dimensions.pack(side='left', pady=5)
        entry_fields = tk.Frame(frame)
        entry_fields.pack(side='right', pady=5)

        tk.Label(dimensions, text="length:", font=normal_font).pack(pady=3)
        tk.Label(dimensions, text="width:", font=normal_font).pack(pady=4)
        tk.Label(dimensions, text="height:", font=normal_font).pack(pady=4)
        tk.Label(dimensions, textvariable=self.v).pack()
        tk.Entry(entry_fields, textvariable=self.length).pack(pady=6)
        tk.Entry(entry_fields, textvariable=self.width).pack(pady=6)
        tk.Entry(entry_fields, textvariable=self.height).pack(pady=6)

        ttk.Button(self, text="calculate", command=self.calculate).pack()
        ttk.Button(self, text="Page 2", command=lambda: controller.show_frame(PageTwo)).pack()
        ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage)).pack()

    def calculate(self):
        try:
            l = float(self.length.get())
            b = float(self.width.get())
            h = float(self.height.get())
            m = l*b*h
            self.v.set("volume: % .2f m³" % m)
            self.Pages.p = m
        except ValueError:
            tk.messagebox.showinfo('No valid input.', 'Please enter only numbers!', icon = 'warning')


class PageTwo(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        # normal_font = ("Arial", 11)  # not used
        self.Pages = Pages()
        title = tk.Label(self, text="Please select the bottom abilities.", font=LARGE_FONT)
        title.pack(pady=10, padx=10)
        self.bottomMaterial = tk.StringVar()
        self.bottom = tk.StringVar()
        self.wallMaterial = tk.StringVar()
        self.wall = tk.StringVar()
        frame = tk.Frame(self)
        frame.pack(pady=20)
        dimensions = tk.Frame(frame)
        dimensions.pack(side='left', pady=5)
        tk.Entry(dimensions, textvariable=self.bottom).grid(pady=5)
        self.cboBottomMaterial = ttk.Combobox(dimensions, textvariable=self.bottomMaterial,
                                              state='readonly', font=('arial', 14, 'bold'), width=19)
        self.cboBottomMaterial['value'] = ('Parkett', 'Linoleum', 'PVC')
        self.cboBottomMaterial.current(0)
        self.cboBottomMaterial.grid()
        ttk.Button(dimensions, text="OK", command=self.get_bottom_choice).grid()
        tk.Entry(dimensions, textvariable=self.wall).grid(pady=5)
        self.cboWallMaterial = ttk.Combobox(dimensions, textvariable=self.wallMaterial,
                                            state='readonly', font=('arial', 14, 'bold'), width=19)
        self.cboWallMaterial['value'] = ('Tapete', 'Glattputz', 'Mauerziegelwand')
        self.cboWallMaterial.current(0)
        self.cboWallMaterial.grid()

        ttk.Button(dimensions, text="OK", command=self.get_wall_choice).grid()
        ttk.Button(self, text="sum", command=self.sum_absorption_area).pack()
        ttk.Button(self, text="Page 1", command=lambda: controller.show_frame(PageOne)).pack()
        ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage)).pack()
        ttk.Button(self, text="Page 3", command=lambda: controller.show_frame(PageThree)).pack()

    def get_bottom_choice(self):
        if self.cboBottomMaterial.get() == "Parkett":
            parkett_125 = self.Pages.parkett_125 * float(self.bottom.get())
            parkett_250 = self.Pages.parkett_250 * float(self.bottom.get())
            parkett_500 = self.Pages.parkett_500 * float(self.bottom.get())
            parkett_1000 = self.Pages.parkett_1000 * float(self.bottom.get())
            parkett_2000 = self.Pages.parkett_2000 * float(self.bottom.get())
            parkett_4000 = self.Pages.parkett_4000 * float(self.bottom.get())
            return sum([parkett_125, parkett_250, parkett_500, parkett_1000, parkett_2000, parkett_4000])
        elif self.cboBottomMaterial.get() == "Linoleum":
            linoleum_125 = self.Pages.linoleum_125 * float(self.bottom.get()),
            linoleum_250 = self.Pages.linoleum_250 * float(self.bottom.get())
            linoleum_500 = self.Pages.linoleum_500 * float(self.bottom.get())
            linoleum_1000 = self.Pages.linoleum_1000 * float(self.bottom.get())
            linoleum_2000 = self.Pages.linoleum_2000 * float(self.bottom.get())
            linoleum_4000 = self.Pages.linoleum_4000 * float(self.bottom.get())
            return sum([linoleum_125, linoleum_250, linoleum_500, linoleum_1000, linoleum_2000, linoleum_4000])
        elif self.cboBottomMaterial.get() == "PVC":
            pvc_250 = self.Pages.pvc_250 * float(self.bottom.get()),
            pvc_500 = self.Pages.pvc_500 * float(self.bottom.get())
            pvc_1000 = self.Pages.pvc_1000 * float(self.bottom.get())
            pvc_2000 = self.Pages.pvc_2000 * float(self.bottom.get())
            pvc_4000 = self.Pages.pvc_4000 * float(self.bottom.get())
            return sum([pvc_250, pvc_500, pvc_1000, pvc_2000, pvc_4000])
        elif self.cboBottomMaterial.get() == "":
            messagebox.showinfo('No valid input.', 'Please select.', icon='warning')
            return 0

    def get_wall_choice(self):
        if self.cboWallMaterial.get() == "Tapete":
            tapete_125 = self.Pages.tapete_125 * float(self.wall.get())
            tapete_250 = self.Pages.tapete_250 * float(self.wall.get())
            tapete_500 = self.Pages.tapete_500 * float(self.wall.get())
            tapete_1000 = self.Pages.tapete_1000 * float(self.wall.get())
            tapete_2000 = self.Pages.tapete_2000 * float(self.wall.get())
            tapete_4000 = self.Pages.tapete_4000 * float(self.wall.get())
            return sum([tapete_125, tapete_250, tapete_500, tapete_1000, tapete_2000, tapete_4000])
        elif self.cboWallMaterial.get() == "Glattputz":
            glattputz_125 = self.Pages.glattputz_125 * float(self.wall.get())
            glattputz_250 = self.Pages.glattputz_250 * float(self.wall.get())
            glattputz_500 = self.Pages.glattputz_500 * float(self.wall.get())
            glattputz_1000 = self.Pages.glattputz_1000 * float(self.wall.get())
            glattputz_2000 = self.Pages.glattputz_2000 * float(self.wall.get())
            glattputz_4000 = self.Pages.glattputz_4000 * float(self.wall.get())
            return sum([glattputz_125, glattputz_250, glattputz_500, glattputz_1000, glattputz_2000, glattputz_4000])
        elif self.cboWallMaterial.get() == "Mauerziegelwand":
            mauerziegelwand_250 = self.Pages.mauerziegelwand_250 * float(self.wall.get())
            mauerziegelwand_500 = self.Pages.mauerziegelwand_500 * float(self.wall.get())
            mauerziegelwand_1000 = self.Pages.mauerziegelwand_1000 * float(self.wall.get())
            mauerziegelwand_2000 = self.Pages.mauerziegelwand_2000 * float(self.wall.get())
            mauerziegelwand_4000 = self.Pages.mauerziegelwand_4000 * float(self.wall.get())
            return sum([mauerziegelwand_250, mauerziegelwand_500, mauerziegelwand_1000,
                        mauerziegelwand_2000, mauerziegelwand_4000])
        elif self.cboWallMaterial.get() == "":
            messagebox.showinfo('No valid input.', 'Please select.', icon='warning')
            return 0

    def sum_absorption_area(self):
        the_sum = self.get_bottom_choice() + self.get_wall_choice()
        print(the_sum)


class PageThree(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.Pages = Pages()
        self.s = tk.StringVar()
        self.result_var = tk.StringVar()
        self.selected_var = tk.StringVar()
        self.selected_var.set("No selection")
        self.result_var.set("No result")
        self.abs_rate = tk.StringVar()
        items_for_listbox = ["Musik", "Sprache", "Vortrag", "Spr.+Vor.", "Sport"]

        frame = tk.Frame(self)
        frame.pack(pady=20)
        self.dimension = tk.Frame(frame)
        self.dimension.pack(side='left', pady=5)
        tk.Label(self, text="Page 2", font=LARGE_FONT).pack(pady=10, padx=10)
        tk.Label(self.dimension, textvariable=self.abs_rate).pack()
        tk.Label(self.dimension, textvariable=self.s).pack()
        tk.Label(self.dimension, textvariable=self.selected_var).pack(expand='yes')
        tk.Label(self.dimension, textvariable=self.result_var).pack(expand='yes')

        listbox_frame = tk.Frame(self.dimension)
        listbox_frame.pack(expand='yes')
        self.mylistbox = tk.Listbox(listbox_frame, height=5, width=10, font=('times', 18))
        self.mylistbox.bind('<<ListboxSelect>>', self.select)
        self.mylistbox.grid(row=0, column=0)
        self.mylistbox.insert('end', *items_for_listbox)

        scroll = tk.Scrollbar(listbox_frame, orient='vertical')  # the alignment of the scrollbar
        self.mylistbox["yscrollcommand"] = scroll.set  # link the list with the scroll
        scroll["command"] = self.mylistbox.yview  # link the scroll with the scroll
        scroll.grid(row=0, column=1, sticky='ns')  # sticky=N+S+E)

        tk.Button(self.dimension, text="Fläche der Absorber", command=self.calc).pack(expand='yes')
        ttk.Button(self, text="Start Page", command=lambda: controller.show_frame(StartPage)).pack()
        ttk.Button(self, text="Page 1", command=lambda: controller.show_frame(PageOne)).pack()
        ttk.Button(self, text="Page 2", command=lambda: controller.show_frame(PageTwo)).pack()
        ttk.Button(self, text="pasvariable", command=self.pass_variable).pack()
        ttk.Button(self, text="pass absorption rate", command=self.absorptions_rate).pack()

    def curselection(self, a):
        if a == "Musik":
            return 0.45 * math.log10(self.Pages.p) + 0.07
        elif a == "Sprache":
            return 0.37 * math.log10(self.Pages.p) - 0.14
        elif a == "Vortrag":
            return 0.32 * math.log10(self.Pages.p) - 0.17
        elif a == "Spr.+Vor.":
            return 0.26 * math.log10(Pages.p) - 0.14
        elif a == "Sport":
            return 0.75 * math.log10(Pages.p) - 1

    def calc(self):
        if self.mylistbox.get('active'):
            abs_fl_ges = 0.163 * Pages.p / Pages.z
            absorber = abs_fl_ges - Pages.abs_flä
            self.result_var.set(absorber)

        elif Pages.z == 0:
            messagebox.showinfo("No selection")

    def select(self, _=None):
        a = self.mylistbox.get('anchor')
        self.Pages.z = self.curselection(a)
        self.selected_var.set(self.Pages.z)

    def pass_variable(self):
        self.s.set("volume: % .2f m³" % self.Pages.p)

    def absorptions_rate(self):
        self.abs_rate.set("volume: % .2f m³" % self.Pages.abs_flä)


if __name__ == '__main__':
    ReverberationTime().mainloop()

我一眼就看到2期。您没有将tkinter作为tk导入,并且您的缩进不正确。这应该是4个空格,因为代码中有很多错误!即使是导入也很混乱——从tkinter import*开始,然后在类中混响timetk.TKYou发布了太多的代码。请创建一个。Stackoverflow不是完整程序的免费调试服务。你需要专注于一个小问题,并包含足够的代码来说明这个问题。@Mike SMT:你提到的这些都不是错误,都是个人偏好。虽然如果他们坚持最佳实践会很好,但这与所问的问题并不相关。@BryanOakley导入是错误的。它们使用tk.tk,但不作为tk导入。他们也在使用messagebox,但也不导入它。首先,我很惊喜你能如此迅速、热情地帮助我。谢谢大家。好的,我看到你使用了另一种策略。在类页面中定义所有变量,而不使用任何方法,因此可以在类页面2中直接更改变量的值。但不幸的是,它不起作用。当我点击底部选择的上方OK按钮时,我得到一个错误。下方的“确定”按钮未连接,如果我单击它,则没有反应。最后,sum_absorption_area-function没有做任何事情::这里是错误:`File E:/Python/Akustik/Akustik/Test2.py,第185行,在get_bottom_选项返回和[pvc_250,pvc_500,pvc_1000,pvc_2000,pvc_4000]TypeError:不支持+:'int'和'tuple'的操作数类型`Jionny odd。这一错误在我这边没有发生。我想知道元组是从哪里来的。我有个会议要去,但我回来后会再看一眼。告诉我你正在使用什么插补,你期望得到什么,我回来后会看一看。只是想让你们知道,当我按下sum键时,我会在屏幕上打印一个没有错误的值。所以,也许这是你正在使用的某个特定的东西,我需要尝试。现在我在Spyder和Jupyter笔记本中尝试了它,都描述了这个错误:也许我做错了什么。。。好的,待会儿见@Jionny你用的是什么插补?