Ok, I'll wait for your solution. In the meantime, I'try to find a way to solve the problem, but I think this is waste of time. hahaha...
This is the latest version of the code,including your improvements:
This is the latest version of the code,including your improvements:
import math from tkinter import ( Tk, ttk, messagebox, StringVar, Label, Listbox, Scrollbar, Button, Frame, ACTIVE, ANCHOR, BOTH, END, YES, N, S, VERTICAL, ) l = 9.92 # Länge b = 10.5 # Breite h = 2.34 # Höhe A = l*b # Nutzfläche = Deckenfläche : 104.16m² A_f = 30.45 # Fensterfläche A_w = 2*(l*h)+2*(h*b) - A_f # Wandfläche insgesamt: 65.12m² V = l*b*h # 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" # Variables z = 1 items_for_listbox = ["Musik","Sprache","Vortrag","Spr.+Vor.","Sport"] def Abs_Materialen(x): for n in range (x): if x == 1: Abs_Wand = Wand*(0.03+ 0.03+ 0.03+ 0.04+ 0.05+ 0.06)/6 return(Abs_Wand) if x == 2: Abs_Wand = Wand*(0.11+ 0.22+ 0.34+ 0.35+ 0.51+ 0.43)/6 return(Abs_Wand) if x == 3: Abs_Wand = Wand*(0.02+ 0.02+ 0.03+ 0.03+ 0.04+ 0.06)/6 return(Abs_Wand) if x == 4: Abs_Wand = Wand*(0.03+ 0.03+ 0.02+ 0.04+ 0.05+ 0.05)/6 return(Abs_Wand) if x == 11: Abs_Boden = Boden*(0.04+ 0.04+ 0.05+ 0.06+ 0.06+ 0.06)/6 return(Abs_Boden) if x == 12: Abs_Boden = Boden*(0.20+ 0.15+ 0.10+ 0.09+ 0.06+ 0.10)/6 return(Abs_Boden) if x == 13: Abs_Boden = Boden*(0.15+ 0.08+ 0.07+ 0.06+ 0.06+ 0.06)/6 return(Abs_Boden) if x == 14: Abs_Boden = Boden*(0.02+ 0.04+ 0.07+ 0.19+ 0.29+ 0.35)/6 return(Abs_Boden) if x == 10: Abs_Fenster = Fenster*(0.28+ 0.20+ 0.11+ 0.06+ 0.03+ 0.02)/6 return(Abs_Fenster) def Abs_Objekte(x): for n in range (x): if x == 1: Abs_MP = MP*(0.15+ 0.25+ 0.55+ 0.80+ 0.90+ 0.90)/6 return(Abs_MP) if x == 2: Abs_WP = WP*(0.05+ 0.10+ 0.15+ 0.35+ 0.45+ 0.60)/6 return(Abs_WP) if x == 3: Abs_Stuhl = Stuhl*(0.05+ 0.15+ 0.20+ 0.10+ 0.03+ 0.03)/6 return(Abs_Stuhl) # Eingabe der Flächen in m²: Boden = 100 Decke = 100 Wand = 180 Fenster = 80 WP = 18 # Weibliche Person MP = 19 # Männliche Person Stuhl = WP + MP Abs_Fläche = Abs_Materialen(4)+ Abs_Materialen(11) +Abs_Objekte(1) + Abs_Objekte(2)+ Abs_Objekte(3) Abs_Fläche #------------------------ 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 ------------------------- def select(event): global z #a = int(mylistbox.get(tk.ANCHOR)) a = mylistbox.get(ANCHOR) z = curselection(a) selected_var.set(z) def curselection(a): if a=="Musik": T_soll_A1 = 0.45*math.log10(V)+0.07 return (T_soll_A1) elif a=="Sprache": T_soll_A2 = 0.37*math.log10(V)-0.14 return (T_soll_A2) elif a=="Vortrag": T_soll_A3 = 0.32*math.log10(V)-0.17 return (T_soll_A3) elif a=="Spr.+Vor.": T_soll_A4 = 0.26*math.log10(V)-0.14 return (T_soll_A4) elif a=="Sport": T_soll_A5 = 0.75*math.log10(V)-1 return (T_soll_A5) def calculate(): global z if mylistbox.get(ACTIVE): Abs_Fl_ges = 0.163 * V / z # gemäß Sabinesche Formel:T_soll = (0163*V)/A_abs Absorber = Abs_Fl_ges - Abs_Fläche result_var.set(Absorber) elif z == 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()