Bonjour,
pour récupérer la valeur de l'option "foreground" du tag "1" de mon widget Text nommé champTexte, je lui applique la méthode suivante:
j'obtiens le message d'erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part print(champTexte.cget(1, "foreground"))
j'ai trouvé cette réponse, mais je ne sais pas comment l'exploiter!TypeError: cget() takes 2 positional arguments but 3 were given
par ailleurs, ceci ne fonctionne pas mieux:
Code : Sélectionner tout - Visualiser dans une fenêtre à part print(champTexte.cget(1, "-foreground"))
https://groups.google.com/forum/?fro...on/Mi2HMOaGtEE
Merci de me dépanner!> The tag_cget method of the Text widget needs preceding hyphen in the
> argument, such as:
>
> text.tag_cget('-background')
>
> It seems inconsistent with the other cget methods of widgets. Is this a
> bug?
Oops, yes!
Try this version:
def tag_cget(self, tagName, option):
if option[:1] != '-':
option = '-' + option
if option[-1:] == '_':
option = option[:-1]
return self.tk.call(self._w, 'tag', 'cget', tagName, option)
--Guido van Rossum (home page: http://www.python.org/~guido/)
Partager