How to import a numerical variable inside a function from another file - Python
I'm trying to create a welding throat calculator just to practice my Python skills. I have 2 files for the same project, throat_size.py and support.py. I use support.py, just to make the calculus that I need, and I want to call these results throat_size, but I'm getting: name 'a' is not defined.
throat_size.py:
import tkinter as tk
import support as sp
firstWindowResults = []
firstWindow = tk.Tk()
w = 650
p = 470
ws = firstWindow.winfo_screenwidth() # width of the screen
hs = firstWindow.winfo_screenheight() # height of the screen
x = (ws/2) - (w/2)
y = (hs/2) - (p/2)
firstWindowTitle = tk.Label(firstWindow, text="Cordões de soldadura")
firstWindowTitle.grid(column=1, row=0, padx=10, pady=10)
firstInput = tk.Label(firstWindow, text="Menor espessura a soldar")
firstInput.grid(column=0, row=3, padx=10, pady=10)
espessura = tk.Entry(firstWindow)
espessura.grid(column=1, row=3, padx=10, pady=10)
firstWindowValues = [espessura]
def validateFirstWindowValues():
invalid = 0
firstWindowResults.clear()
for value in firstWindowValues:
if value == espessura:
if float(value.get()) <= 0:
entry = firstWindowValues.index(value) + 1
tk.messagebox.showerror("Valor inválido", "Ver linha " + str(entry) + "!")
invalid += 1
break
else:
firstWindowResults.append(value.get())
if invalid == 0:
sp.thickness(firstWindowResults[0])
Res = "a = " + sp.a1
#Passo 3: Loop
nextButton = tk.Button(firstWindow, text="Enter", command=validateFirstWindowValues)
nextButton.grid(column=1, row=9, padx=10, pady=10)
firstWindow.geometry('%dx%d+%d+%d' % (w, p, x, y))
firstWindow.mainloop()
support.py:
import math as mt
def thickness(espessura):
global a1, rz1, z1, a2, rz2, z2
rz1, rz2 = 0.5, 0.7
a1 = float(espessura) * rz1
z1 = 2 * mt.cos(mt.radians(45)) * a1
a2 = float(espessura) * rz2
z2 = 2 * mt.cos(mt.radians(45)) * a2
Comments
Post a Comment