Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3919 connectés 

  FORUM HardWare.fr
  Programmation
  Python

  Tkinter récupérer une variable radio bouton dans un label

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Tkinter récupérer une variable radio bouton dans un label

n°2222545
docbour
Timeo hominem unius libri
Posté le 18-03-2014 à 12:42:54  profilanswer
 

Débutant en Python, mon premier programme avec Tkinter bloque sur la récupération d'une variable d'un champ radio button dans une autre fenetre type Label.
J'arrive à récupérer ma variable avec .get() et l'imprimer mais pas à l'inclure dans le Label. J'ai essayé de passer par une fonction, un lambda sans succès.
 
Voici le type de programme que j'utilise:
 
from tkinter import *
 
fen = Tk()
global var
var = IntVar()
 
def result():
    print(var.get())
     
donnee = lambda var: var.get()
 
bouton_1 = Radiobutton(fen, text="jaune", variable=var, value=1, command=result)
bouton_2 = Radiobutton(fen, text="vert", variable=var, value=2, command=result)
 
bouton_1.pack()
bouton_2.pack()
 
champ_label = Label(fen, bg='white', text=donnee, font=("Comic Sans MS","10","bold" ),relief=FLAT)
champ_label.pack()
 
fen.mainloop()
 

mood
Publicité
Posté le 18-03-2014 à 12:42:54  profilanswer
 

n°2222572
masklinn
í dag viðrar vel til loftárása
Posté le 18-03-2014 à 16:34:16  profilanswer
 

docbour a écrit :

Débutant en Python, mon premier programme avec Tkinter bloque sur la récupération d'une variable d'un champ radio button dans une autre fenetre type Label.
J'arrive à récupérer ma variable avec .get() et l'imprimer mais pas à l'inclure dans le Label. J'ai essayé de passer par une fonction, un lambda sans succès.
 
Voici le type de programme que j'utilise:
 
from tkinter import *
 
fen = Tk()
global var
var = IntVar()
 
def result():
    print(var.get())
     
donnee = lambda var: var.get()
 
bouton_1 = Radiobutton(fen, text="jaune", variable=var, value=1, command=result)
bouton_2 = Radiobutton(fen, text="vert", variable=var, value=2, command=result)
 
bouton_1.pack()
bouton_2.pack()
 
champ_label = Label(fen, bg='white', text=donnee, font=("Comic Sans MS","10","bold" ),relief=FLAT)
champ_label.pack()
 
fen.mainloop()
 


http://infohost.nmt.edu/tcc/help/p [...] ables.html

Citation :

Label
You can set its textvariable option to a StringVar. Then any call to the variable's .set() method will change the text displayed on the label.


[:petrus75]
 
(accessoirement, ton "global var" sert strictement à rien)


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2222597
docbour
Timeo hominem unius libri
Posté le 18-03-2014 à 20:00:28  profilanswer
 

Merci, j'ai compris le principe mais je n'arrive pas encore à le mettre en pratique

n°2222610
masklinn
í dag viðrar vel til loftárása
Posté le 18-03-2014 à 20:59:59  profilanswer
 

Suffit de remplacer text=donnee par textvariable=var, j'ai du mal à percevoir ce qu'il y a à mettre en pratique.


Message édité par masklinn le 18-03-2014 à 21:00:16

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°2222628
docbour
Timeo hominem unius libri
Posté le 19-03-2014 à 08:57:59  profilanswer
 

Super, c'est ce que je cherchais.
Je n'avais pas saisi la différence entre "text" et "text variable"
Merci


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Python

  Tkinter récupérer une variable radio bouton dans un label

 

Sujets relatifs
Html / Asp Afficher une variableclic et logique booléenne avec tkinter
Réponse SQL variableRécupérer un "Return" Javascript dans un input
Recuperer le select d'une autocompletion[Java] Image dans un bouton
Windows Forms bouton pictureboxRécuperer ID MySQL
Opération sur colonne variablerécupérer un login et un mot de passe dans deux tables différentes
Plus de sujets relatifs à : Tkinter récupérer une variable radio bouton dans un label


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)