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