Mar-04-2022, 11:18 PM
I dont mean it as a complaint but i like it when you guys comes with sopheticated answers like this.
Its clearly meant to teach me the proper way to implement class and attributes and i tha nk you for that. But its not solving the main issue.
Its clearly meant to teach me the proper way to implement class and attributes and i tha nk you for that. But its not solving the main issue.
from tkinter import * class Temperature: def __init__(self, valeur): self.valeur = valeur def conversionF(self): if choix.get() == 'Celcius à Fahrenheit': resultat = float((9 * self.valeur) / 5 + 32) return resultat.configure(text=str(fahrenheit)) else: return self.conversionC(self) ///////// <------i still want to know if it is logical and possible to that. def conversionC(self): resultat = float((self.valeur - 32) * 5 / 9) return 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') valeur = Temperature(valeur = str(entree.get())) ///<----instead of a number i want to fit my method to input the temperature. ///How do i do that. 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) 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()There must be an easy way to fix that code without reformating the whole thing. I get the bid picture, its the small details that slows me.