⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Canvas
tkinter.Canvas ( ).select_item ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Canvas
tkinter.Canvas ( ).select_item ( )
DESCRIPTION.
Retourne l'identifiant numérique de l'élément texte ayant la sélection active d'une zone de dessin.
SYNTAXE.
Variable = CAN_Toile.select_item ( )
Variable = ⇨ variable qui recevra la valeur [ optionnel ]
CAN_Toile ⇨ instance quelconque de tkinter.Canvas ( ) [ OBLIGATOIRE ]
.select_item ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
REMARQUES.
Si aucun élément texte n'a de sélection active au moment de l'appel, la méthode tkinter.Canvas ( ).select_item ( ) retourne None.
EXEMPLE.
import tkinter
def FNC_Selection ( event ) :
if TKV_Texte.get ( ) == "" : return
CAN_Carte.select_from ( TKV_Texte.get ( ) , SCA_Debut.get ( ) )
CAN_Carte.select_to ( TKV_Texte.get ( ) , SCA_Fin.get ( ) - 1 )
def FNC_Texte ( event ) :
CAN_Carte.focus_set ( )
TKV_Texte.set ( CAN_Carte.find_withtag ( "current" ) [ 0 ] )
ktexte = CAN_Carte.itemcget ( TKV_Texte.get ( ) , "text")
SCA_Debut [ "to" ] = len ( ktexte ) - 1
SCA_Fin [ "to" ] = len ( ktexte )
LAB_Ligne [ "text" ] = ktexte
CAN_Carte.focus ( TKV_Texte.get ( ) )
FNC_Selection ( None )
LAB_Element [ "text" ] = f"Sélection sur l'élément : { CAN_Carte.select_item ( ) }"
TKI_Principal = tkinter.Tk ( )
TKV_Texte = tkinter.StringVar ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
SCA_Debut = tkinter.Scale ( TKI_Principal , to = 1 , orient = "horizontal" , command = FNC_Selection )
SCA_Fin = tkinter.Scale ( TKI_Principal , from_ = 1 , to = 2 , orient = "horizontal" , command = FNC_Selection )
LAB_Element = tkinter.Label ( TKI_Principal , text = "Sélection sur l'élément : ?" , relief = "ridge" , bd = 3 )
LAB_Ligne = tkinter.Label ( TKI_Principal , text = "Cliquez sur une ligne." , relief = "ridge" , bd = 3 , height = 2 )
CAN_Carte = tkinter.Canvas ( TKI_Principal , bg = "white" , width = 200 , height = 100 )
CAN_Carte.create_text ( 100 , 30 , text = "Mon Python à moi." , fill = "orange" )
CAN_Carte.create_text ( 100 , 50 , text = "Un Python pour tous." )
CAN_Carte.create_text ( 195 , 95 , text = "Origine NERD" , anchor = "se" , fill = "blue" )
CAN_Carte.grid ( row = 0 , column = 0 , columnspan = 2 , sticky = "nesw" )
LAB_Element.grid ( row = 1 , column = 0 , columnspan = 2 , sticky = "nesw" )
LAB_Ligne.grid ( row = 2 , column = 0 , columnspan = 2 , sticky = "nesw" )
tkinter.Label ( TKI_Principal , text = "Début : " , justify = "right" ).grid ( row = 3 , column = 0 , sticky = "se" )
SCA_Debut.grid ( row = 3 , column = 1 , sticky = "nesw" )
tkinter.Label ( TKI_Principal , text = "Fin : " , justify = "right" ).grid ( row = 4 , column = 0 , sticky = "se" )
SCA_Fin.grid ( row = 4 , column = 1 , sticky = "nesw" )
BUT_Quitter.grid ( row = 5 , column = 0, columnspan = 2 , sticky = "nesw" )
CAN_Carte.tag_bind ( "current" , "<ButtonRelease-1>" , FNC_Texte )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de