IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

boutons radio et utilisation


Sujet :

Tkinter Python

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut boutons radio et utilisation
    bonjour
    je suis actuellement en terminal et je j'ai un programme isn a finir
    je bloc au niveau de l'utilisation de mes boutons radio...en gros je veux faire un jeux du style little professor( jeux de calcul pour enfants), j'ai donc le debut de mon interface graphique, et meme le plus gros. J'ai des boutons radios qui definissent le mode ( addition soustraction division multiplication) et le niveau ( qui definit les nombre qui seront utilsées pour l'opperation, plus le niveau est grand plus les chiffres importer aleatoirement le sont aussi), le problemes c est que j'ai un bouton qui appelle une fonction qui va lire les boutons radio et puis va faire afficher mes deux variables de l'opération, or la facon dont je les utilise ne marche pas car j'arrive pas a passer dans la boucle.... je vous met mon programme ci dessous, si quelqu'un arrivait a voir ce qu'il va pas et me le dire, ca serait super sympa...
    merci d 'avance
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
     
    from tkinter import *
    import random
     
    def evaluer(event):
        chaine.configure(text='Résultat = '+str(eval(entree.get())))
     
     
     
    fenetre = Tk()
    fenetre['bg']='white'
     
     
     
     
     
     
    def fonctionboutonradio(): 
        global variable1
        global variable2
        x=mode.get()            #je pense que l'utilisation des boutons radio ne se fait pas de cette maniere
        y=niveau.get()          
        if x==1 and y==6:       #en effet, si cela marchais ainsi et que je selectionnais le mode addition et le niveau 1 je passerai par la forcement 
            variable1=random.randint(1,9)                                               #ainsi variable1 et 2 prendrais de nouvelles valeur diferent de 0
            variable2=random.randint(1,9)
            enonce= Label(fenetre, background='white',text=str(variable1))              #et la il s'afficherait forcement quelque chose... 
            enonce.pack(side=LEFT, padx=30, pady=30)                                    #et en lancant le programme vous verrez que rien ne s'affiche
            enonce= Label(fenetre, background='white',text="+")                         #conclusion: x est different de 1 et y de 6 car on ne passe pas dans cette boucle
            enonce.pack(side=LEFT, padx=31, pady=30)                                    #ducoup pourriez vous reregarder  dans vos programme comment on utilise les radio bouton????                                   
            enonce= Label(fenetre, background='white',text=str(variable2))
            enonce.pack(side=LEFT, padx=32, pady=30)
        if x==1 and y==7:
            variable1=random.randint(10,20)
            variable2=random.randint(10,20)
        if x==1 and y==8:
            variable1=random.randint(21,30)
            variable2=random.randint(21,30)
        if x==1 and y==9:
            variable1=random.randint(31,40)
            variable2=random.randint(31,40)
        if x==1 and y==10:
            variable1=random.randint(41,50)
            variable2=random.randint(41,50)
     
     
     
     
     
     
     
     
     
     
    mode = StringVar()
    bouton1 = Radiobutton(fenetre, text="Addition", variable=mode, value=1)
    bouton2 = Radiobutton(fenetre, text="Soustraction", variable=mode, value=2)
    bouton3 = Radiobutton(fenetre, text="Multiplication", variable=mode, value=3)
    bouton4 = Radiobutton(fenetre, text="Division", variable=mode, value=4)
    bouton1.pack(side=LEFT, padx=0, pady=2)
    bouton2.pack(side=LEFT, padx=2, pady=2)
    bouton3.pack(side=LEFT, padx=4, pady=2)
    bouton4.pack(side=LEFT, padx=6, pady=2)
     
     
    niveau = StringVar()
    bouton11 = Radiobutton(fenetre, text="niveau 1", variable=niveau, value=6)
    bouton22 = Radiobutton(fenetre, text="niveau 2", variable=niveau, value=7)
    bouton33 = Radiobutton(fenetre, text="niveau 3", variable=niveau, value=8)
    bouton44 = Radiobutton(fenetre, text="niveau 4", variable=niveau, value=9)
    bouton55 = Radiobutton(fenetre, text="niveau 5", variable=niveau, value=10)
    bouton11.pack()
    bouton22.pack()
    bouton33.pack()
    bouton44.pack()
    bouton55.pack()
     
     
     
     
    Frame1 = Frame(fenetre, borderwidth=2, relief=GROOVE)
    Frame1.pack(side=LEFT, padx=30, pady=30)
    Label(Frame1, text="Bonjour, ce pogrammme est un jeu éducatif, qui reprend le principe de little professor, choississez un mode et un niveau",bg="red").pack(padx=10, pady=10)
     
    Boutonradiovaleur = Button(fenetre, text ='definir les nombres aléeatoires', command=fonctionboutonradio )
    Boutonradiovaleur.pack()
     
     
     
     
     
    entree = Entry(fenetre, background='white')
    entree.bind("<Return>", evaluer)
    chaine = Label(fenetre)
    entree.pack()
    chaine.pack()

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    et (bouton1->checked()) ne marche pas

  3. #3
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Salut,

    Faites un print de ce que retourne mode.get() et niveau.get().
    De toutes façons, comme ce sont des StringVar(), vous allez récupérer des "strings" qui comparées à des entiers seront toujours !=.

    - W

  4. #4
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    il me dit que mode et niveau sont pas définie..
    et ducoup pour la chaine de caractere je dois la remplacer par un float?

  5. #5
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 302
    Points : 36 801
    Points
    36 801
    Par défaut
    Citation Envoyé par tomtom42 Voir le message
    il me dit que mode et niveau sont pas définie..
    et ducoup pour la chaine de caractere je dois la remplacer par un float?
    Les valeurs prises sont des entiers (c'est ce que dit votre code en tous cas) donc c'est IntVar et non StringVar

    - W

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    j'ai une derniere question, qui n'est pas en rapport avec le bouton radio, mais pour savoir pourquoi quand on donne le bon résultats il me répond que c'est faux, c'est peut etre une question bete, mais je bloc vraiment

    Code python : 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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
     
    from tkinter import *
    import random
     
     
     
     
    fenetre = Tk()
    fenetre['bg']='white'
     
    def evaluer(event): 
        global variable1
        global variable2
        global variable3
        int(variable1)
        int(variable2)
     
        if entree.get()== variable3 : ##### le probleme est la je pense
            chaine.configure(text='bravo tu as trouvé le bon résultat')
        else:
            chaine.configure(text='essaie encore')
     
     
     
     
    def fonctionboutonradio(): 
        global variable1
        global variable2
        global DELTA
        global variable3
        x=mode.get()            
        y=niveau.get()
     
        if x==1 and y==6 :     
            variable1=random.randint(1,9)                                              
            variable2=random.randint(1,9)
            variable3= variable1+variable2
            DELTA= '+'
     
        if x==1 and y==7:
            variable1=random.randint(10,20)
            variable2=random.randint(10,20)
            variable3= variable1+variable2
            DELTA= '+'
     
        if x==1 and y==8:
            variable1=random.randint(21,30)
            variable2=random.randint(21,30)
            variable3= variable1+variable2
            DELTA= '+'
     
        if x==1 and y==9:
            variable1=random.randint(31,40)
            variable2=random.randint(31,40)
            variable3= variable1+variable2
            DELTA= '+'
     
        if x==1 and y==10:
            variable1=random.randint(41,50)
            variable2=random.randint(41,50)
            variable3= variable1+variable2
            DELTA= '+'
     
        if x==2 and y==6 :     
            variable1=random.randint(1,9)                                              
            variable2=random.randint(1,9)
            variable3= variable-variable2
            DELTA= '-'
     
        if x==2 and y==7:
            variable1=random.randint(10,20)
            variable2=random.randint(10,20)
            variable3= variable1-variable2
            DELTA= '-'
     
        if x==2 and y==8:
            variable1=random.randint(21,30)
            variable2=random.randint(21,30)
            variable3= variable1-variable2
            DELTA= '-'
     
        if x==2 and y==9:
            variable1=random.randint(31,40)
            variable2=random.randint(31,40)
            variable3= variable1-variable2
            DELTA= '-'
     
        if x==2 and y==10:
            variable1=random.randint(41,50)
            variable2=random.randint(41,50)
            variable3= variable1-variable2
            DELTA= '-'
     
        if x==3 and y==6 :     
            variable1=random.randint(1,9)                                              
            variable2=random.randint(1,9)
            variable3= variable1*variable2
            DELTA= '*'
     
        if x==3 and y==7:
            variable1=random.randint(10,20)
            variable2=random.randint(10,20)
            variable3= variable1*variable2
            DELTA= '*'
     
        if x==3 and y==8:
            variable1=random.randint(21,30)
            variable2=random.randint(21,30)
            variable3= variable1*variable2
            DELTA= '*'
     
        if x==3 and y==9:
            variable1=random.randint(31,40)
            variable2=random.randint(31,40)
            variable3= variable1*variable2
            DELTA= '*'
     
        if x==3 and y==10:
            variable1=random.randint(41,50)
            variable2=random.randint(41,50)
            variable3= variable1*variable2
            DELTA= '*'
     
        if x==4 and y==6 :     
            variable3=random.randint(1,9)
            variable2=random.randint(1,9)                                              
            variable1=variable3*variable2
            DELTA= '/'
     
        if x==4 and y==7:
            variable1=random.randint(10,20)
            variable2=random.randint(10,20)
     
            DELTA= '/'
     
        if x==4 and y==8:
            variable1=random.randint(21,30)
            variable2=random.randint(21,30)
     
            DELTA= '/'
     
        if x==4 and y==9:
            variable1=random.randint(31,40)
            variable2=random.randint(31,40)
            DELTA= '/'
     
        if x==4 and y==10:
            variable1=random.randint(41,50)
            variable2=random.randint(41,50)
            DELTA= '/'
     
     
     
    def framevaleur():
        global variable1
        global variable2
        global DELTA
     
        Frame2 = Frame(fenetre, borderwidth=2, relief=GROOVE)
        Frame2.pack(side=BOTTOM , padx=30, pady=30)
        Frame3 = Frame(Frame2, bg="white", borderwidth=2, relief=GROOVE)
        Frame3.pack(side=RIGHT, padx=5, pady=5)
        Frame4 = Frame(Frame2, bg="white", borderwidth=2, relief=GROOVE)
        Frame4.pack(side=RIGHT, padx=5, pady=5)
        Frame5 = Frame(Frame2, bg="white", borderwidth=2, relief=GROOVE)
        Frame5.pack(side=RIGHT, padx=5, pady=5)
        Label(Frame2, text="valeurs").pack(padx=10, pady=10)
        Label(Frame3, text=str(variable1),bg="white").pack(padx=10, pady=10)
        Label(Frame4, text=DELTA ,bg="white").pack(padx=10, pady=10)
        Label(Frame5, text=str(variable2),bg="white").pack(padx=10, pady=10)
        Boutonradiovaleur = Button(Frame2, text ='détruire cette oppération', command=Frame2.destroy )
        Boutonradiovaleur.pack()
     
     
     
     
     
    mode = IntVar()
    bouton1 = Radiobutton(fenetre, text="Addition", variable=mode, value=1)
    bouton2 = Radiobutton(fenetre, text="Soustraction", variable=mode, value=2)
    bouton3 = Radiobutton(fenetre, text="Multiplication", variable=mode, value=3)
    bouton4 = Radiobutton(fenetre, text="Division", variable=mode, value=4)
    bouton1.pack(side=LEFT, padx=0, pady=2)
    bouton2.pack(side=LEFT, padx=2, pady=2)
    bouton3.pack(side=LEFT, padx=4, pady=2)
    bouton4.pack(side=LEFT, padx=6, pady=2)
     
     
    niveau = IntVar()
    bouton11 = Radiobutton(fenetre, text="niveau 1", variable=niveau, value=6)
    bouton22 = Radiobutton(fenetre, text="niveau 2", variable=niveau, value=7)
    bouton33 = Radiobutton(fenetre, text="niveau 3", variable=niveau, value=8)
    bouton44 = Radiobutton(fenetre, text="niveau 4", variable=niveau, value=9)
    bouton55 = Radiobutton(fenetre, text="niveau 5", variable=niveau, value=10)
    bouton11.pack()
    bouton22.pack()
    bouton33.pack()
    bouton44.pack()
    bouton55.pack()
     
     
     
     
    Frame1 = Frame(fenetre, borderwidth=2, relief=GROOVE)
    Frame1.pack(side=LEFT, padx=30, pady=30)
    Label(Frame1, text="Bonjour, ce pogrammme est un jeu éducatif, qui reprend le principe de little professor, choississez un mode et un niveau",bg="red").pack(padx=10, pady=10)
     
    Boutonradiovaleur = Button(fenetre, text ='definir les nombres aléeatoires', command= fonctionboutonradio )
    Boutonradiovaleur.pack()
     
     
    Boutonframe = Button(fenetre, text ='afficher variable', command= framevaleur )
    Boutonframe.pack()
     
     
     
     
     
     
     
     
    entree = Entry(fenetre, background='white')
    entree.bind("<Return>", evaluer)
    chaine = Label(fenetre)
    entree.pack()
    chaine.pack()

Discussions similaires

  1. Comment utiliser les boutons radio?
    Par mamelouk dans le forum Word
    Réponses: 5
    Dernier message: 18/06/2010, 11h34
  2. Utilisation des boutons Radio sous Qt
    Par ZouBi dans le forum Qt
    Réponses: 2
    Dernier message: 28/03/2008, 22h47
  3. [VB6]Utilisation des boutons radio.
    Par Chocapic dans le forum VB 6 et antérieur
    Réponses: 27
    Dernier message: 14/06/2006, 11h48
  4. Réponses: 5
    Dernier message: 29/05/2006, 14h27
  5. [C# 2.0][VS2005] Utilisation des boutons radio
    Par keisuke dans le forum Windows Forms
    Réponses: 13
    Dernier message: 29/04/2006, 17h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo