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 :

Aide calculatrice TKinter


Sujet :

Tkinter Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2019
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2019
    Messages : 16
    Points : 13
    Points
    13
    Par défaut Aide calculatrice TKinter
    Salut,
    Je suis en train de coder une calculatrice pour les projets de fin d'année de mon cours de NSI. J'ai tous les boutons et une zone d'affichage des nombre (on peut afficher des nombres en cliquant sur les boutons), par contre je n'ai aucune idée de comment faire l'addition/soustraction etc
    Quelqu'un pourrait il m'aider ?

    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
    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
     
    #-------------------------------------------------------------------------------
    #Modules importés :
     
    from tkinter import * #Tkinter
    import math #math
    from tkinter.font import Font as f #Font
    import parser #parser
    import tkinter.messagebox #messagebox
     
    #-------------------------------------------------------------------------------
    #Affichage des chiffres
     
    def btnClic(num) :
        global op
        entreTxt.insert(END, num)
     
    def insertDeb(num) :
        global op
        entreTxt.insert(0, num)
     
    #Fonction Clear
    def ClearAff() :
        global op
        op = ""
        entreTxt.delete(0, END)
        chaine.config(text="")
     
    def Egal() :
        pass
     
    #-------------------------------------------------------------------------------
    #Caractérisiques de la fenêtre
     
    root = Tk() #Création de la fenêtre
    root.title("Calculatrice")
    root.geometry("480x568") #On donne une taille de 450x550 px a la fenêtre
     
    #Bloquage la taille de la fenêtre
    root.resizable(width=False, height=False)
     
    #Couleur de fond de la fenêtre
    root.config(background='#2e4053')
     
    #-------------------------------------------------------------------------------
     
    calc = Frame(root)
    calc.grid()
     
    #-------------------------------------------------------------------------------
    #Afficahge des boutons
    entreTxt = Entry(calc, font=('arial', 20, 'bold'), bg="#5d6d7e", bd=30, width=28, justify=RIGHT)
    entreTxt.grid(row=0, column=0, columnspan=4, pady=1)
     
    btn7 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "7", command=lambda:btnClic(7)).grid(row=2, column=0)
    btn8 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "8", command=lambda:btnClic(8)).grid(row=2, column=1)
    btn9 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "9", command=lambda:btnClic(9)).grid(row=2, column=2)
     
    btn4 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "4", command=lambda:btnClic(4)).grid(row=3, column=0)
    btn5 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "5", command=lambda:btnClic(5)).grid(row=3, column=1)
    btn6 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "6", command=lambda:btnClic(6)).grid(row=3, column=2)
     
    btn1 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "1", command=lambda:btnClic(1)).grid(row=4, column=0)
    btn2 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "2", command=lambda:btnClic(2)).grid(row=4, column=1)
    btn3 = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "3", command=lambda:btnClic(3)).grid(row=4, column=2)
    #-------------------------------------------------------------------------------
    #Code gérant les calculs entré au clavier
    def evaluer(event) :
        chaine.configure(text=" " + str(eval(entreTxt.get())))
     
    entreTxt.bind("<Return>", evaluer)
    chaine = Label(root)
    chaine.config(font= f(size=20), bg="#5d6d7e")
    chaine.place(x=30,y=32)
     
    #-------------------------------------------------------------------------------
    #Boutons calculatrice standard
     
    btnclear = Button(calc, text="C", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#85929e", command=lambda:ClearAff()).grid(row=1, column=0, pady=1)
     
    btnEx2 = Button(calc, text="²", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:btnClic("**2")).grid(row=1, column=1, pady=1)
     
    btnSqrt = Button(calc, text="√", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", ).grid(row=1, column=2, pady=1)
     
    btnAdd = Button(calc, text="+", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:btnClic("+")).grid(row=1, column=3, pady=1)
     
    btnSous = Button(calc, text="-", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:btnClic("-")).grid(row=2, column=3, pady=1)
     
    btnMult = Button(calc, text="x", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:btnClic("*")).grid(row=3, column=3, pady=1)
     
    btnDiv = Button(calc, text="÷", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:btnClic("/")).grid(row=4, column=3, pady=1)
     
    btnZero = Button(calc, text="0", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command = lambda:btnClic(0)).grid(row=5, column=0, pady=1)
     
    btnVirg = Button(calc, text=".", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command= lambda:btnClic(".")).grid(row=5, column=1, pady=1)
     
    btnPlusMoins = Button(calc, text="±", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e", command=lambda:insertDeb("-")).grid(row=5, column=2, pady=1)
     
    btnEgal = Button(calc, text="=", width=6, height=2, font=("arial",20,"bold"),
                        bd=4, bg="#5d6d7e").grid(row=5, column=3, pady=1)
     
    #-------------------------------------------------------------------------------
    #Boutons mode Scientifique
     
    btnPi = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "π", bg="#5d6d7e", command=lambda:btnClic(round(math.pi, 4))).grid(row=2, column=5)
     
    btnCos = Button(calc, text="cos", width=6, height=2, font=("arial",20,"bold"), bd=4, bg="#5d6d7e").grid(row=2, column=4, pady=1)
     
    btnSin = Button(calc, text="sin", width=6, height=2, font=("arial",20,"bold"), bd=4, bg="#5d6d7e").grid(row=3, column=4, pady=1)
     
    btnTan = Button(calc, text="tan", width=6, height=2, font=("arial",20,"bold"), bd=4, bg="#5d6d7e").grid(row=4, column=4, pady=1)
     
    btnParOuv = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "(", command=lambda:btnClic("(")).grid(row=1, column=4)
     
    btnParFer = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = ")", command=lambda:btnClic(")")).grid(row=1, column=5)
     
    btnExpo = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "^", command=lambda:btnClic("**")).grid(row=5, column=4)
     
    btnExpo = Button(calc, width=6, height=2, font=("arial",20,"bold"), bd=4, text = "1/x").grid(row=5, column=5)
     
     
    #Parenthèses // exposant // pi
     
    #-------------------------------------------------------------------------------
    #Menu
     
    def iExit() :
        iExit = tkinter.messagebox.askyesno("Calculatrice scientifique", "Confirmez si vous voulez quitter")
        if iExit > 0 :
            root.destroy()
            return
     
    def scientifique() :
        root.resizable(width=False, height=False)
        root.geometry("714x568")
     
    def standard() :
        root.resizable(width=False, height=False)
        root.geometry("480x568")
     
     
    menubar = Menu(calc)
     
    filemenu = Menu(menubar, tearoff = 0)
    menubar.add_cascade(label = "File", menu=filemenu)
    filemenu.add_command(label="Standard", command=standard)
    filemenu.add_command(label="Scientifique", command=scientifique)
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=iExit)
     
    root.config(menu=menubar)
     
    #-------------------------------------------------------------------------------
    #Affichage de la fenêtre
     
    root.mainloop()
    Merci d'avance

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    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 287
    Points : 36 776
    Points
    36 776
    Par défaut
    Salut,

    Citation Envoyé par Gal.o.u Voir le message
    par contre je n'ai aucune idée de comment faire l'addition/soustraction etc
    C'est bien de se lancer dans un tel projet mais il n'est pas très original.
    Un peu de recherche sur Internet avec les mots clefs "python calculatrice tkinter" vous permettrait de regarder ce qu'ont déjà fait d'autres et de vous en inspirer.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Aide Calculatrice Tkinter
    Par Hchichus dans le forum Tkinter
    Réponses: 4
    Dernier message: 20/12/2017, 08h32
  2. [Python 3.X] Besoin d'aide pour tkinter jeu taquin
    Par cilouc dans le forum Général Python
    Réponses: 1
    Dernier message: 18/04/2016, 23h04
  3. Aide pour tkinter/console application
    Par _yak_ dans le forum Tkinter
    Réponses: 6
    Dernier message: 30/06/2010, 14h44

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