Feb-19-2020, 11:17 AM
There was more then one error.
A cleaned up version of your code:
Haven't tested much.
A cleaned up version of your code:
Haven't tested much.
import math from tkinter import ( Tk, ttk, messagebox, StringVar, Label, Listbox, Scrollbar, Button, Frame, ACTIVE, ANCHOR, BOTH, END, YES, N, S, VERTICAL, ) length = 9.92 # Länge width = 10.5 # Breite height = 2.34 # Höhe A = length * width # Nutzfläche = Deckenfläche : 104.16m² A_f = 30.45 # Fensterfläche A_w = ( 2 * (length * height) + 2 * (height * width) - A_f ) # Wandfläche insgesamt: 65.12m² V = length * width * height # Volumen des Raumes: 243.73m³ AV = A / V # Verhältnis Fläche zu Volumen: 0.43m² # Constants for the geometry of the main window APP_XPOS = 100 APP_YPOS = 100 APP_WIDTH = 300 APP_HEIGHT = 300 APP_TITLE = "Simple Applikation" NORM_FONT = ("Arial", 16) # Variables items_for_listbox = ["Musik", "Sprache", "Vortrag", "Spr.+Vor.", "Sport"] def abs_materialen(x): for n in range(x): if x == 1: return Wand * (0.03 + 0.03 + 0.03 + 0.04 + 0.05 + 0.06) / 6 if x == 2: return Wand * (0.11 + 0.22 + 0.34 + 0.35 + 0.51 + 0.43) / 6 if x == 3: return Wand * (0.02 + 0.02 + 0.03 + 0.03 + 0.04 + 0.06) / 6 if x == 4: return Wand * (0.03 + 0.03 + 0.02 + 0.04 + 0.05 + 0.05) / 6 if x == 11: return Boden * (0.04 + 0.04 + 0.05 + 0.06 + 0.06 + 0.06) / 6 if x == 12: return Boden * (0.20 + 0.15 + 0.10 + 0.09 + 0.06 + 0.10) / 6 if x == 13: return Boden * (0.15 + 0.08 + 0.07 + 0.06 + 0.06 + 0.06) / 6 if x == 14: return Boden * (0.02 + 0.04 + 0.07 + 0.19 + 0.29 + 0.35) / 6 if x == 10: return Fenster * (0.28 + 0.20 + 0.11 + 0.06 + 0.03 + 0.02) / 6 def abs_objekte(x): for n in range(x): if x == 1: return MP * (0.15 + 0.25 + 0.55 + 0.80 + 0.90 + 0.90) / 6 if x == 2: return WP * (0.05 + 0.10 + 0.15 + 0.35 + 0.45 + 0.60) / 6 if x == 3: return Stuhl * (0.05 + 0.15 + 0.20 + 0.10 + 0.03 + 0.03) / 6 Boden = 100 Decke = 100 Wand = 180 Fenster = 80 WP = 18 # Weibliche Person MP = 19 # Männliche Person Stuhl = WP + MP abs_flaeche = ( abs_materialen(4) + abs_materialen(11) + abs_objekte(1) + abs_objekte(2) + abs_objekte(3) ) # ------------------------ popup ----------------------------------- def popupmsg(msg): popup = Tk() popup.wm_title("!") popup.iconbitmap("C:/Users/PC/Desktop/Icons/attention.ico") ttk.Label(popup, text=msg, font=NORM_FONT).pack(side="top", fill="x", pady=10) ttk.Button(popup, text="Okay", command=popup.destroy).pack() popup.mainloop() # -----------------------------calculating ------------------------- # noinspection PyUnusedLocal def select(event): global width # a = int(mylistbox.get(tk.ANCHOR)) a = mylistbox.get(ANCHOR) width = curselection(a) selected_var.set(width) def curselection(a): if a == "Musik": return 0.45 * math.log10(V) + 0.07 elif a == "Sprache": return 0.37 * math.log10(V) - 0.14 elif a == "Vortrag": return 0.32 * math.log10(V) - 0.17 elif a == "Spr.+Vor.": return 0.26 * math.log10(V) - 0.14 elif a == "Sport": return 0.75 * math.log10(V) - 1 def calculate(): global width if mylistbox.get(ACTIVE): abs_fl_ges = ( 0.163 * V / width ) # gemäß Sabinesche Formel:T_soll = (0163*V)/A_abs absorber = abs_fl_ges - abs_flaeche result_var.set(absorber) elif width == 0: messagebox.showinfo("No selection") # GUI # App window app_win = Tk() app_win.title(APP_TITLE) app_win.wm_geometry("%dx%d+%d+%d" % (APP_WIDTH, APP_HEIGHT, APP_XPOS, APP_YPOS)) # Main container embeded in the app window # Container for all of the app widgets main_frame = Frame(app_win) main_frame.pack(expand=YES, fill=BOTH) # Label to show your listbox selection selected_var = StringVar() Label(main_frame, textvariable=selected_var, font=("times", 12, "bold")).pack( expand=YES ) selected_var.set("No selection") # Label to show your calculated result result_var = StringVar() Label(main_frame, textvariable=result_var, font=("times", 12, "bold")).pack(expand=YES) result_var.set("No result") # Container for the listbox & scrollbar (embeded in the main frame) listbox_frame = Frame(main_frame) 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 allignment 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) # Button to launch a calculation button = Button(main_frame, text="Fläche der Absorber", command=calculate).pack( expand=YES ) app_win.mainloop()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!