Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Re: une fonction pour creer des fonction ???

1 réponse
Avatar
oliv
J'ai testé
from Tkinter import

class Callback

def __init__(self‚function‚argument)
self.function = functio
self.argument = argumen

def __call__(self)
self.function(self.argument

def show(arg)
print “Je suis le bouton %s” %ar

root = Tk(
for x in range(10)
Button(root‚text='Bouton %s' %x‚command=lambda x=x:show(x)).pack(

root.mainloop(

Mais ça ne marche pas, y a t-il une erreur dans le code
merc

--
oliv

-----------------------------------------------------------------------
Voir theme: http://www.frbox.net/viewtopic-518350.htm

Envoyé de http://www.frbox.ne

1 réponse

Avatar
Pierre Quentel
J'ai testé :
from Tkinter import *

class Callback:

def __init__(self‚function‚argument):
self.function = function
self.argument = argument

def __call__(self):
self.function(self.argument)

def show(arg):
print “Je suis le bouton %s” %arg

root = Tk()
for x in range(10):
Button(root‚text='Bouton %s' %x‚command=lambda x=x:show(x)).pack()

root.mainloop()

Mais ça ne marche pas, y a t-il une erreur dans le code ?
merci


Ben si, à l'indentation près ça marche

Tu as quoi comme trace d'erreur ?