So i'm writing a program that converts currencies for a school projects. I tried using as many loops and references to make the program as short as possible. But i keep getting error
"UnboundLocalError: local variable 'v3' referenced before assignment".
Here's the code(note: i trimmed it down so it's just the necessary part).
from tkinter import *
root = Tk()
btn1 = StringVar()
btn2 = StringVar()
VALUTE = [ #besedilo v gumbu, oznaka, tečaj
("Evro", "evrov", 1),
("Dolar", "dolarjev", 1.12005),
("Funt", "funtov", 0.739868547),
]
v = v2 = v3 = v4 = 1
def funkcija():
n = int(entry1.get())
X = btn1.get()
Y = btn2.get()
for text, mark, convert in VALUTE:
if v3 == X:
o = convert
E = mark
v3 = v3 + 1
if v4 == Y:
p = convert
F = mark
v4 = v4 + 1
m = pretvorba(o,p)
print("%s %s je %s %s." % (n, E, m, F))
def pretvorba(a,b):
Q = n/a*b
return Q
for text, mark, convert in VALUTE:
gumb = Radiobutton(root, text=text, value = v, variable = btn1).grid(row = v+1, column=1, sticky=W)
v=v+1
for text, mark, convert in VALUTE:
gumb = Radiobutton(root, text=text, value = v2, variable = btn2).grid(row = v2+6, column=1, sticky=W)
v2=v2+1
entry1 = Entry(root)
entry1.grid(row=1, column=1, sticky=W)
go = Button(root, text="Izračun", fg="white", bg="black", command=funkcija)
go.grid(row=10, columnspan=3)
root.mainloop()