'How to fix the position of the code, its not working
How to call the get method after the user has entered any data? I tried many things and I am so upset because this is the main computational function in my program.
I am trying to transmute grades and my main problem here is that I cannot convert the string to float/int so the process cannot be continued in any way.
def gen_avg():
# new window again
genWin = Toplevel(ws)
# sets the title of the new window
genWin.title("Class Record Program | General Avg")
# sets the geometry of toplevel
genWin.geometry("750x400")
# change window bg
genWin.config(bg='#FFF0F5')
# frm
frame2 = Frame(
genWin,
padx=40,
pady=50
)
frame2.pack(pady=20)
Label(
frame2,
text='My name | Quarterly Grades'
).grid(row=0, column=1)
Label(
frame2,
text="ICT Q1 Grade: "
).grid(row=1, column=0)
Label(
frame2,
text="ICT Q2 Grade: "
).grid(row=2, column=0)
Label(
frame2,
text="ICT Q3 Grade: "
).grid(row=3, column=0)
Label(
frame2,
text="ICT Q4 Grade: "
).grid(row=4, column=0)
Q1_tf = Entry(
frame2,
font = ('sans-sherif', 15)
)
Q2_tf = Entry(
frame2,
font = ('sans-sherif', 15)
)
Q3_tf = Entry(
frame2,
font = ('sans-sherif', 15)
)
Q4_tf = Entry(
frame2,
font = ('sans-sherif', 15)
)
# position the entry boxes
Q1_tf.grid(row=1, column=1)
Q2_tf.grid(row=2, column=1)
Q3_tf.grid(row=3, column=1)
Q4_tf.grid(row=4, column=1)
Q1 = Q1_tf.get()
Q2 = Q2_tf.get()
Q3 = Q3_tf.get()
Q4 = Q4_tf.get()
Button(
frame2,
text="Compute General Avg.",
pady=4,
padx=30,
command=(genAvg)
).grid(row=5, columnspan=2)
Button(
frame1,
text='Display Transmuted Grade',
pady=4,
padx=40,
command = disp
).grid(row=12, columnspan=2)
Button(
frame1,
text='General Avg.',
pady=4,
padx=30,
command=(gen_avg)
).grid(row=13, columnspan=3)
def genAvg():
gen = int((Q1)+(Q2)+(Q3)+(Q4))
genz = float(gen/4)
# dang this took a lot of time -Transmutation table-
if (genz) < (75):
pF = 'Student does not have a passing grade this school year.'
# short version of the transmutation table bc its unnecessary
pf = str(pF)
time.sleep(2)
Label(
frame2,
text =(pf)
).grid(row=5, column=1)
Error
File "C:\PYTHON\Python310\rr.py", line 430, in genAvg gen = int((Q1)+(Q2)+(Q3)+(Q4)) NameError: name 'Q1' is not defined
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
