ich schreibe zur Zeit ein Programm zum berechnen der freiwerdenden Energie einer Kernreaktion.
Die Benutzeroberfläche funktioniert zwar einwandfrei und ich komme auch an die Werte der Scales,
jedoch kann ich die Entrys zur Eingabe der Edukt- und Produktmassen nicht auslesen.
Ich erhalte lediglich die Fehlermeldung: "NameError: name 'massE_1' is not defined"
Hier ist mein bisheriger Code:
Code: Alles auswählen
import tkinter.font as tkf
from tkinter import *
'''
#Formeln
E = 'm*c**2'
m = 'M*n'
n = 'N/A'
#Konstanten
A = 6.02214086*10**23
J_eV = 6.24*10**18
eV_J = 1.67*10**-19
'''
#andere
EPnumbers = list(range(1, 5))
M_alphaE = 0
M_betaE = 0
M_neutronE = 0
M_alphaP = 0
M_betaP = 0
M_neutronP = 0
def Interface():
def value_alpha_E (value):
global M_alphaE
M_alphaE = (2*(2*(2.3*10**6)+4.8*10**6)+2*(2*(4.8*10**6))+2.3*10**6)*float(value)
def value_beta_E (value):
global M_betaE
M_betaE = 0.511*10**6*float(value)
def value_neutron_E(value):
global M_neutronE
M_neutronE = (2.3*10**6+2*4.8*10**6)*float(value)
def value_alpha_P (value):
global M_alphaP
M_alphaP = (2*(2*(2.3*10**6)+4.8*10**6)+2*(2*(4.8*10**6))+2.3*10**6)*float(value)
def value_beta_P (value):
global M_betaP
M_betaP = 0.511*10**6*float(value)
def value_neutron_P(value):
global M_neutronP
M_neutronP = (2.3*10**6+2*4.8*10**6)*float(value)
def calculate():
print(M_alphaE, M_betaE, M_neutronE, M_alphaP, M_betaP, M_neutronP)
print(massE_1)
GUI = Tk()
GUI.wm_title('Energy-Calculator')
#GUI.iconbitmap('atom.ico')
#Schriftarten
Font_h = tkf.Font(family = 'Arial', size = 50)
Font_c = tkf.Font(family = 'Arial', size = 10)
#Frames
top = Frame(GUI)
main = Frame(GUI)
bottom = Frame(GUI)
#content_top
header = Label(top, text = 'Energy Calculator', font = Font_h)
#Edukte
for n in EPnumbers:
exec('Edukt_' + str(n) + ' = Frame(main) ')
exec('titleE_' + str(n) + ' = Label(master = Edukt_' + str(n) + ', text = "Masse Edukt' + str(n) + '", font = Font_c)')
exec('massE_' + str(n) + ' = Entry(Edukt_' + str(n) + ')')
exec('Edukt_' + str(n) + '.grid(column = ' + str(n) + ', row = 0, pady = 20)')
exec('titleE_' + str(n) + '.pack()')
exec('massE_' + str(n) + '.pack()')
n_alphaE = Label(main, text = '\u03B1', font = Font_c)
n_betaE = Label(main, text = '\u03B2', font = Font_c)
n_neutronenE = Label(main, text = 'n' , font = Font_c)
n_alphaE .grid(column = 1, row = 1)
n_betaE .grid(column = 2, row = 1)
n_neutronenE.grid(column = 3, row = 1)
alphaE = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_alpha_E )
betaE = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_beta_E )
neutronE = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_neutron_E)
alphaE .grid(column = 1, row = 2)
betaE .grid(column = 2, row = 2)
neutronE.grid(column = 3, row = 2)
#Produkte
for n in EPnumbers:
exec('Produkt_' + str(n) + ' = Frame(main) ')
exec('titleP_' + str(n) + ' = Label(master = Produkt_' + str(n) + ', text = "Masse Produkt' + str(n) + '", font = Font_c)')
exec('massP_' + str(n) + ' = Entry(Produkt_' + str(n) + ')')
exec('Produkt_' + str(n) + '.grid(column = ' + str(n) + ', row = 3, pady = 20)')
exec('titleP_' + str(n) + '.pack()')
exec('massP_' + str(n) + '.pack()')
n_alphaP = Label(main, text = '\u03B1', font = Font_c)
n_betaP = Label(main, text = '\u03B2', font = Font_c)
n_neutronenP = Label(main, text = 'n' , font = Font_c)
n_alphaP .grid(column = 1, row = 4)
n_betaP .grid(column = 2, row = 4)
n_neutronenP.grid(column = 3, row = 4)
alphaP = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_alpha_P )
betaP = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_beta_P )
neutronP = Scale(main, from_ = 0, to = 10, orient = HORIZONTAL, command = value_neutron_P)
alphaP .grid(column = 1, row = 5)
betaP .grid(column = 2, row = 5)
neutronP.grid(column = 3, row = 5)
start = Button(bottom, text = 'BERECHNEN', font = Font_c, command = calculate)
start.grid(column = 0, row = 0, pady = 20)
#positioning_Frames
top .grid(column = 0, row = 1)
main .grid(column = 0, row = 2)
bottom.grid(column = 0, row = 3)
#positioning_top
header.pack()
GUI.mainloop()
Interface()