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 :

Besoin d'aide sur Int float et autre


Sujet :

Tkinter Python

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Juin 2019
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 21
    Localisation : France, Gers (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Juin 2019
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Besoin d'aide sur Int float et autre
    Bonjour,
    Je suis débutant sur python et j'aimerais réaliser un programme avec tkinter pour calculer des polynômes du second degré, j'ai d'abord créé un programme de calcul :
    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
    from math import *
    a=int(input("Entrez a="))
    b=int(input("Entrez b="))
    c=int(input("Entrez c="))
    d=(b**2-(4*a*c))
    if d > 0:
        print("Delta = ",d)
        print("Delta est supérieur à 0 donc nous pouvons en déduire les racines : ")
        print("x1 = (-b-sqrt(delta))/2a et","x2 = (-b+sqrt(delta))/2a")
        x1=((-b-sqrt(d))/(2*a))
        x2=((-b+sqrt(d))/(2*a))
        print("Donc x1 = ",x1,"et x2 = ",x2)
    elif d == 0:
        print("Delta = 0")
        print("Delta est égal à 0 donc nous pouvons en déduire une racine : ")
        print("x1 = -b/2a")
        x3=-b/(2*a)
        print("Donc x1 = ",x3)
    else:
        print("Delta est inférieur à 0 donc nous ne pouvons pas en déduire de racines")
    Ce programme est fonctionnel, mais dans la console, or j'aimerais une interface graphique, voici ce que j'ai fait :
    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
     
    from tkinter import *
     
    window = Tk()
     
    window.title("Menu")
    window.geometry("1280x720")
    window.minsize(480, 360)
    window.iconbitmap("calculator.ico")
    window.config(background='#3c3838')
     
     
    def apparitiontoppol():
        pol = Toplevel(window)
        pol.title("Polinôme du second degré")
        pol.geometry("1280x720")
        pol.minsize(480, 360)
        pol.iconbitmap("line-graph.ico")
        pol.config(background='#3c3838')
        lab = Label(pol, text="Polynôme du second degré :", font=("Arial", 40, "bold", "underline"), bg='#3c3838', fg='white')
        lab.pack()
        e1 = Label(pol, text="a=", font=("Arial", 40), bg='#3c3838', fg='white')
        e1.pack()
        a_entry = Entry(pol, font=("Arial", 25), bg='#3c3838', fg='white')
        a_entry.pack()
        e2 = Label(pol, text="b=", font=("Arial", 40), bg='#3c3838', fg='white')
        e2.pack()
        b_entry = Entry(pol, font=("Arial", 25), bg='#3c3838', fg='white')
        b_entry.pack()
        e3 = Label(pol, text="c=", font=("Arial", 40), bg='#3c3838', fg='white')
        e3.pack()
        c_entry = Entry(pol, font=("Arial", 25), bg='#3c3838', fg='white')
        c_entry.pack()
        a_entry1 = a_entry.get()
        a_entryint = int(float(a_entry1))
        b_entry1 = b_entry.get()
        b_entryint = int(float(b_entry1))
        c_entry1 = c_entry.get()
        c_entryint = int(float(c_entry1))
     
        def calculpol():
            from math import sqrt
            d = (b_entryint ** 2 - (4 * a_entryint * c_entryint))
            if d > 0:
                delt = Label(pol, text="Delta =", textvariable=d)
                delt.pack()
                x1 = ((-b_entryint - sqrt(d)) / (2 * a_entryint))
                x2 = ((-b_entryint + sqrt(d)) / (2 * a_entryint))
                print("Donc x1 = ", x1, "et x2 = ", x2)
            elif d == 0:
                x3 = -b_entryint / (2 * a_entryint)
                print("Donc x1 = ", x3)
            else:
                print("Delta est inférieur à 0 donc nous ne pouvons pas en déduire de racines")
     
        calc = Button(pol, text="Calculer", font=("Arial", 25), bg='#3c3838', fg='white', command=calculpol)
        calc.pack()
     
     
    frame = Frame(window, bg='#3c3838')
     
    label_title = Label(frame, text="Sélectionnez une opération :", font=("Arial", 40, "bold"), bg='#3c3838', fg='white')
    label_title.pack()
     
    poli_button = Button(frame, text="Polynôme du second degré", command=apparitiontoppol, font=("Arial", 40, "bold"), bg='white', fg='#3c3838')
    poli_button.pack(pady=25)
     
    mxp_button = Button(frame, text="y=mx+p", font=("Arial", 40, "bold"), bg='white', fg='#3c3838')
    mxp_button.pack(pady=25)
     
    frame.pack(expand=YES)
     
    window.mainloop()
    Voici l'intégralité du programme, quand je le lance une erreur apparait " line 35, in apparitiontoppol
    a_entryint = int(float(a_entry1))
    ValueError: could not convert string to float: "
    Après recherches je n'ai rien trouvé, aidez moi svp , de plus si vous constatez d'autre problèmes dans le code n'hésitez pas à le dire,
    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,

    Relisez le message d'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ValueError: could not convert string to float: "
    Le string étant la chaine vide i.e. le contenu des Entry qui viennent juste d'être créées.

    Pourtant vous avez créée un Button "Calculer" qui permet à l'utilisateur de lancer le calcul après qu'il ait saisi ses valeurs (et c'est à ce moment là qu'on peut espérer récupérer quelque chose dans les Entry, pas avant).

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

Discussions similaires

  1. [D7] Besoin d'aide sur un PChar
    Par bobby-b dans le forum Langage
    Réponses: 6
    Dernier message: 30/06/2004, 16h42
  2. Filemaker ... besoin d'aide sur les Plugin
    Par joange dans le forum Autres SGBD
    Réponses: 3
    Dernier message: 22/04/2004, 10h16
  3. [intermedia] besoin d'aide sur script PL/SQL
    Par SteelBox dans le forum PL/SQL
    Réponses: 8
    Dernier message: 05/01/2004, 19h59
  4. [CR] besoin d'aide sur les formules
    Par GuillaumeDSA dans le forum Formules
    Réponses: 4
    Dernier message: 10/07/2003, 12h19

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