Bonjour,
J'aimerais "lire la valeur du bouton radio" sélectionné, or lorsque je le lis, ça ne m'écrit rien..
J'ai pourtant regardé plusieurs site, et ils font bien comme moi.
Voici mon code:
Code complet:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 # -*- coding: cp1252 -*- from Tkinter import * #import de tkinter fenetre = Tk() #création de la fenêtre tkinter label = Label(fenetre, text="TEST", pady=10) #Bienvenue label.pack() #afficher label var_choix = StringVar() choix_rouge = Radiobutton(fenetre, text="Rouge", variable=var_choix, value="rouge") choix_vert = Radiobutton(fenetre, text="Vert", variable=var_choix, value="vert") choix_bleu = Radiobutton(fenetre, text="Bleu", variable=var_choix, value="bleu") choix_rouge.pack() choix_vert.pack() choix_bleu.pack() print var_choix.get() #BOUTON POUR VALIDER LES SAISIES ET QUITTER LA FENETRE bouton_quitter = Button(fenetre, text="Valider", command=fenetre.quit) bouton_quitter.pack() fenetre.mainloop() fenetre.mainloop()
Ce code fonctionne, mais c'est quand j'ajoute autre chose que ça ne fonctionne plus..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 #!/usr/bin/env python # -*- coding: utf-8 -*- # -*- coding: cp1252 -*- import cookielib, urllib, urllib2, time #import des outils from Tkinter import * #import de tkinter fenetre = Tk() #création de la fenêtre tkinter Frame1 = LabelFrame(fenetre, text="...", padx=1, pady=1, borderwidth=2) Frame1.pack() f01 = Frame(Frame1) Label(f01, text="...", pady=1).pack() Label(f01, text="...", pady=10).pack() f01.pack() fenetre = Tk() label = Label(fenetre, text="...", pady=10) label.pack() Frame1 = LabelFrame(fenetre, text="...", padx=10, pady=10, borderwidth=2) Frame1.pack() f01 = Frame(Frame1) Label(f01, text="...").pack() var_texte = StringVar() r = Entry(f01, textvariable=var_texte, width=30) r.pack() Label(f01, text="...").pack() var_choix = StringVar() Radiobutton(f01, text="Rouge", variable=var_choix, value="rouge").pack() Radiobutton(f01, text="Vert", variable=var_choix, value="vert").pack() Radiobutton(f01, text="Bleu", variable=var_choix, value="bleu").pack() Label(f01, text="...").pack() s = Spinbox(f01, from_=0, to=1000) s.pack() f01.pack() bouton_quitter = Button(fenetre, text="Valider", command=fenetre.quit) bouton_quitter.pack() fenetre.mainloop() print var_choix.get() print r.get() print s.get() fenetre.mainloop()
Merci d'avance pour votre aide !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from Tkinter import * fenetre = Tk() Frame1 = LabelFrame(fenetre, text="...", padx=10, pady=10, borderwidth=2) Frame1.pack() f01 = Frame(Frame1) retour0 = StringVar() bouton1 = Radiobutton(f01, text="...", variable=retour0, value="www") bouton2 = Radiobutton(f01, text="...", variable=retour0, value="es") bouton3 = Radiobutton(f01, text="...", variable=retour0, value="de") bouton1.grid() bouton2.grid() bouton3.grid() f01.pack() bouton_quitter = Button(fenetre, text="Valider", command=fenetre.quit) bouton_quitter.pack() fenetre.mainloop() print retour0.get()
Cordialement,
Python_addict
Partager