1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ########## Importer les modules necessaires ############## from tkinter import * from tkinter.font import Font from random import randrange ########################################################## ########## Fonctions ################################## ########################################################## def rect(i): Canevas.create_text( 500 + 150 * i, 500 ,text = i,fill = "red" ,font = Mapolice) ########################################################## ########## Variables ################################## ########################################################## Couleur = [ "black" , "red" , "blue" ] ######################################################### ########## Interface graphique ########################## ########################################################## Mafenetre = Tk() Mafenetre.title( "Titre" ) Canevas = Canvas(Mafenetre,width = 1000 ,height = 1000 ,bg = 'white' ) Canevas.pack() bouton1 = Button(Mafenetre, text = "1" , command = lambda : rect( 1 )) bouton1.place(x = 100 ,y = 200 ) bouton2 = Button(Mafenetre, text = "2" , command = lambda : rect( 2 )) bouton2.place(x = 200 ,y = 200 ) Mapolice = Font(family = 'Liberation Serif' , size = 200 ) # création d'une police pour l'affichage du texte ########################################################### ########### Receptionnaire d'évènement #################### ########################################################### ###################### FIN ############################### Mafenetre.mainloop() |
Cela permet d'utiliser un paramêtre dans les fonctions Button, bind, ....