Mar-05-2022, 09:38 PM
(This post was last modified: Mar-05-2022, 09:38 PM by deanhystad.)
Actually we've explained this over and over and over. One last try.
The error message could not be any more descriptive.
The function conversionF(self) has an argument named "self". When you press the conversion button you call conversionF() without passing any arguments. Your function call is "missing 1 required positional argument".
But this is not the error. This error is one of two things. Either conversionF() is supposed to be a method of class Temperature, or it is supposed to be a standalone function.
Either your program should look more like this:
The error message could not be any more descriptive.
The function conversionF(self) has an argument named "self". When you press the conversion button you call conversionF() without passing any arguments. Your function call is "missing 1 required positional argument".
But this is not the error. This error is one of two things. Either conversionF() is supposed to be a method of class Temperature, or it is supposed to be a standalone function.
Either your program should look more like this:
import tkinter as tk class Temperature: """All classes should have a docstring describing their purpose""" def __init__(self): self.valeur = 0 # Indentation is important. Needs to be indented to same level as __init__() def conversionF(self): """Methods should also have docstrings""" fahrenheit = float((9 * self.valeur) / 5 + 32) return resultat.configure(text=str(fahrenheit)) def conversionC(self): """To describe what they do""" celcius = float((self.valeur - 32) * 5 / 9) return resultat.configure(text=str(celcius)) # This is not part of class temperature because it is indented the same level as "class Temperature" fen1 = tk.Tk() matemp = Temperature() entree = tk.Entry(fen1).pack() resultat = tk.Label(fen1, text='') resultat.pack() tk.Button(fen1, text='Conversion', command=matemp.conversionF).pack() fen1.mainloop()Or it should look more like this:
import tkinter as tk # Treating this as a function. There is no temperature class anymore def conversionF(): """Methods should also have docstrings""" fahrenheit = float((9 * valuer) / 5 + 32) return resultat.configure(text=str(fahrenheit)) def conversionC(): """To describe what they do""" celcius = float((valuer - 32) * 5 / 9) return resultat.configure(text=str(celcius)) # These should not all be global variables fen1 = tk.Tk() valuer = 0 entree = tk.Entry(fen1).pack() resultat = tk.Label(fen1, text='') resultat.pack() tk.Button(fen1, text='Conversion', command=conversionF).pack() fen1.mainloop()Both programs convert 0 to something. Both programs are still riddled with logic errors.