Hello,
Its been a few hours i am struggling with this code. I am having a hard time understanding the use of classes and constructors.
What does it mean?
Its been a few hours i am struggling with this code. I am having a hard time understanding the use of classes and constructors.
from tkinter import * class Temperature: valeur = 0 def __init__(self, valeur): self.valeur = valeur def conversionF(self): if choix.get() == 'Celcius à Fahrenheit': resultat = float((9 * self.valeur) / 5 + 32) resultat.configure(text=str(fahrenheit)) else: def conversionC(self): resultat = float((self.valeur - 32) * 5 / 9) resultat.configure(text=str(celcius)) def changement(event): if choix.get() == 'Celcius à Fahrenheit': txt1.configure(text='Température en Celcius') txt2.configure(text='Température en Fahrenheit') else: txt2.configure(text='Température en Celcius') txt1.configure(text='Température en Fahrenheit') fen1 = Tk() fen1.title('Conversion') txt1 = Label(fen1, text='Température en Fahrenheit') txt1.grid(row=0, column=0, sticky=E) entree = Entry(fen1) entree.grid(row=0, column=1) txt2 = Label(fen1, text='Température en Celcius') txt2.grid(row=1, column=0, sticky=E) resultat = Label(fen1, text='') resultat.grid(row=1, column=1) bouton = Button(fen1, text='Conversion', command = conversionF) bouton.grid(row=2, column=0) bouton = Button(fen1, text='Conversion', command = conversionC) bouton.grid(row=2, column=0) choix = StringVar(fen1) choix.set('Celcius à Fahrenheit') liste = OptionMenu(fen1, choix, 'Celcius à Fahrenheit', 'Fahrenheit à Celcius', command=changement) liste.grid(row=2, column=1) fen1.mainloop()I get this error message about conversionC() missing 1 required positional argument: 'self'
What does it mean?