Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
class, attribute and method
#1
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.

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?
Reply


Messages In This Thread
class, attribute and method - by Frankduc - Feb-26-2022, 05:15 PM
RE: class, attribute and method - by ibreeden - Feb-26-2022, 06:45 PM
RE: class, attribute and method - by deanhystad - Feb-26-2022, 07:55 PM
RE: class, attribute and method - by Frankduc - Feb-26-2022, 09:15 PM
RE: class, attribute and method - by snippsat - Feb-26-2022, 10:55 PM
RE: class, attribute and method - by deanhystad - Feb-27-2022, 04:04 AM
RE: class, attribute and method - by Frankduc - Feb-27-2022, 02:15 PM
RE: class, attribute and method - by deanhystad - Feb-27-2022, 06:22 PM
RE: class, attribute and method - by Frankduc - Feb-27-2022, 08:02 PM
RE: class, attribute and method - by deanhystad - Feb-27-2022, 09:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing method attributes of python class Abedin 6 594 Apr-14-2025, 07:02 AM
Last Post: buran
  Difference between method and attribute holding a function ulrich 2 902 Jun-30-2024, 08:35 AM
Last Post: snippsat
  class definition and problem with a method HerrAyas 2 1,422 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 2,349 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  Initiating an attribute in a class __init__: question billykid999 8 2,961 May-02-2023, 09:09 PM
Last Post: billykid999
  Using one child class method in another child class garynewport 5 3,158 Jan-11-2023, 06:07 PM
Last Post: garynewport
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,890 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 3,574 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  Class Method to Calculate Age Doesn't Work gdbengo 1 2,498 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  anonymous method in a class Skaperen 8 4,868 May-23-2021, 11:17 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020