I'm a newbie to Python's Tkinter, and I'd like to create a program running on it. However, my code doesn't work correctly.
from tkinter import *
def conv1(self):
gbp0 = 174000000
galleons0 = 34000872
sickles0 = 14
knuts0 = 7
galleons1 = float(galleons0 + sickles0 / 17 + knuts0 / 29 / 17)
fracture = float(gbp0 / galleons1)
convert1 = Toplevel(root)
convert1.title("Pounds Sterling (GBP) to Galleons, Sickles and Knuts Converter")
label1_1 = Label(convert1, text="Type the amount of money in GBP that you would like to convert to Galleons, Sickles and Knuts and press Enter.")
label1_2 = Label(convert1, text="1 Galleon = 5.12 GBP")
label1_3 = Label(convert1, text='GBP:')
label1_1.pack()
label1_2.pack()
label1_3.pack()
usergbpvar = DoubleVar()
usergbp = Entry(convert1, textvariable=usergbpvar)
usergbp.pack()
a = float(usergbpvar.get() / fracture)
galleons = int(a // 1)
a = (a % 1) * 17
sickles = int(a // 1)
a = (a % 1) * 29
if (a % 1) == 0.5:
knuts = int(round(a, 0))
knuts += 1
else:
knuts = int(round(a, 0))
galleons, sickles, knuts = str(galleons), str(sickles), str(knuts)
label1_4 = Label(convert1, text=galleons)
label1_5 = Label(convert1, text=sickles)
label1_6 = Label(convert1, text=knuts)
label1_4.pack()
label1_5.pack()
label1_6.pack()
convert1.mainloop()
root = Tk()
btn1 = Button(root, text='GBP to Galleons, Sickles and Knuts', bg='#555', fg='#ccc', font='16')
btn1.pack()
btn1.bind('<Button-1>', conv1)
root.mainloop()
It's supposed to calculate three numbers out of the entered one, and to show them on the screen. However, when I run the program, after pressing the button I see that all the numbers are already there and they are 0. After I enter my number, nothing is changed.
Could you please tell me where the issue in my code is?