CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

SUIVIS : Python 2.7.7 + Tkinter

Plixx50
Plixx50
Niveau 8
03 avril 2016 à 11:34:31

Bonjours à tous et à toute, je suis en terminale S spécialité ISN, j'ai donc un projet de fin d'année a réaliser, et j'ai choisis le python avec Tkinter.

Mon programme est simple, est éducatif, c'est un générateur de fenetre de calcul mentaux aléatoire à réaliser, il y a des additions, des soustractions puis je vais m'attaquer aux multiplications et divisions d'ici peu puis un mélange de tout. Seulement je le sais déjà, je risque d'être confroté a des problèmes graphiques :

J'ai envie de faire un style écolier avec pygame ou n'importe quel autre add-on de python dans le quel on metterait en fond une ardoise avec le calcul qui s'écrit d'une police / taille convenable et que la boite de la spinbox ne soit pas trop visible, je sais pas si vous voyez l'idée ? En gros j'ai envie de faire en sorte que ce soit très propre. L'idéal serait qu'on voit une craie / brosse passer pour écrire / effacer le calcul mais là, je n'y crois pas.

Cependant je suis déjà confronté a des petits problèmes graphiques, j'ai écrit plusieurs texte pour avoir : Addditionnez variable A
a
Variable B
seulement cela s'écrit sur trois ligne, j'aimerai bien le mettre sur une ligne.
J'ai aussi un soucis vis à vis d'un bouton, qui écrit Réessaye en cas d'erreur, si la personne fait plusieurs erreur, le mot réessaye se réécrira en dessous, et ça rend un aspect graphique peu agréable, j'aimerai faire en sorte que ça efface la ligne de texte précedente MAIS qu'on voit quand même que c'est une autre erreur et non un bug du programme comme si plus rien ne marchait.

J'ai un niveau peu élevé en python et j'aimerai garder un codage assez simple pour que je puisse l'expliquer aisaiment.

Je vous passe donc les lignes de code, et merci d'avance de votre aide :

from Tkinter import * # <== Importe Tkinter

fen = Tk() #<== Défini la fenêtre

tex = Label(fen, text="Bienvenue sur notre programme de calculs mentaux", fg="white", bg="black") #tex => définis la variable; Label(fen, text) Affiche le texte; FG=FrontGround; BG=BackGround
tex.pack() #<==Affiche le texte dans une fenetre
tex2 = Label(fen, text="Vous allez avoir le choix entre tout les types de calcul, la difficulté sera croissante au fur et à mesure des calculs", fg="white", bg="black")
tex2.pack()


    
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------


def window():#<== défini la commande "Window"
    global s
    global c
    global fen2
    fen2 = Tk()
    import random
    a = random.randint (0,100)
    b = random.randint (0,100)
    c = a+b
    tex = Label(fen2, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fen2, text=a, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen2, text="+", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen2, text=b, fg="white", bg="black")
    tex2.pack() 
    print c
    #MODIFIER LA MISE EN PAGE ULTERIEUREMENT
    

    s = Spinbox(fen2, from_=0, to=1000)
    s.pack()
    Bouton7=Button(fen2, text="Proposer", command=test)
    Bouton7.pack()
def test():
    global s
    global c
    global fen2
    # Récupère la valeur de S et de C des autres fonctions
    v = int(s.get())
    
    if v == c :
        blablabla()
        fen2.destroy()
    else :
        tex5 = Label(fen2, text="Réessaye", fg="white", bg="black")
        tex5.pack()
#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------        
def blablabla():
    global s2
    global c2
    global fenQ
    fenQ = Tk()
    import random
    a2 = random.randint (50,150)
    b2 = random.randint (50,150)
    c2 = a2+b2
    tex = Label(fenQ, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fenQ, text=a2, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQ, text="+", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQ, text=b2, fg="white", bg="black")
    tex2.pack()
    print c2

    s2 = Spinbox(fenQ, from_=0, to=1000)
    s2.pack()
    Bouton7bis=Button(fenQ, text="Proposer", command=testbis)
    Bouton7bis.pack()


def testbis():
    global s2
    global c2
    global fenQ
    v2 = int(s2.get())
    if v2 == c2 :
        bla()
        fenQ.destroy()
    else :
        tex56 = Label(fenQ, text="Réessaye", fg="white", bg="black")
        tex56.pack()

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------    
def bla():
    global s3
    global c3
    global fenQQ
    fenQQ = Tk()
    import random
    a3 = random.randint (75,175)
    b3 = random.randint (75,175)
    c3 = a3+b3
    tex = Label(fenQQ, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fenQQ, text=a3, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQQ, text="+", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQQ, text=b3, fg="white", bg="black")
    tex2.pack()
    print c3

    s3 = Spinbox(fenQQ, from_=0, to=1000)
    s3.pack()
    Bouton7bis=Button(fenQQ, text="Proposer", command=testbiss)
    Bouton7bis.pack()



def testbiss():
    global s3
    global c3
    global fenQQ
    v3 = int(s3.get())
    if v3 == c3 :
        blabla()
        fenQQ.destroy()
    else :
        tex56 = Label(fenQQ, text="Réessaye", fg="white", bg="black")
        tex56.pack()
    



#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------



def blabla():
    global s4
    global c4
    global fenQQQ
    fenQQQ = Tk()
    import random
    a4 = random.randint (100,200)
    b4 = random.randint (100,200)
    c4 = a4+b4
    tex = Label(fenQQQ, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fenQQQ, text=a4, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQQQ, text="+", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQQQ, text=b4, fg="white", bg="black")
    tex2.pack()
    print c4

    s4 = Spinbox(fenQQQ, from_=0, to=1000)
    s4.pack()
    Bouton7bis=Button(fenQQQ, text="Proposer", command=testbisss)
    Bouton7bis.pack()



def testbisss():
    global s4
    global c4
    global fenQQQ
    v4 = int(s4.get())
    if v4 == c4 :
        bla5()
        fenQQQ.destroy()
    else :
        tex56 = Label(fenQQQ, text="Réessaye", fg="white", bg="black")
        tex56.pack()



#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------        

def bla5():
    global s5
    global c5
    global fenQ5
    fenQ5 = Tk()
    import random
    a5 = random.randint (0,1000)
    b5 = random.randint (0,1000)
    c5 = a5+b5
    tex = Label(fenQ5, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fenQ5, text=a5, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQ5, text="+", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fenQ5, text=b5, fg="white", bg="black")
    tex2.pack()
    print c5

    s5 = Spinbox(fenQ5, from_=0, to=10000)
    s5.pack()
    Bouton7bis=Button(fenQ5, text="Proposer", command=testbis5)
    Bouton7bis.pack()



def testbis5():
    global s5
    global c5
    global fenQ5
    v5 = int(s5.get())
    if v5 == c5 :
        blaA6()
        fenQ5.destroy()
    else :
        tex56 = Label(fenQ5, text="Réessaye", fg="white", bg="black")
        tex56.pack()




#------------------------------------------------------------------------------------------------------------------------------------------------------------

def blaA6():
    global s6
    global c6
    global fenA6
    
    fenA6 = Tk()
    

    import random
    a6 = random.randint (-1000,1000)
    b6 = random.randint (-1000,1000)
    c6 = a6+b6
    tex = Label(fenA6, text="Vous pouvez désormais quitter le jeu à tout moment", fg="white", bg="black")
    tex.pack()
    tex = Label(fenA6, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex = Label(fenA6, text=a6, fg="white", bg="black")
    tex.pack()
    tex = Label(fenA6, text="+", fg="white", bg="black")
    tex.pack()
    tex = Label(fenA6, text=b6, fg="white", bg="black")
    tex.pack()
    print c6

    s6 = Spinbox(fenA6, from_=-5000, to=10000)
    s6.pack()
    Bouton7bis=Button(fenA6, text="Proposer", command=testA6)
    Bouton7bis.pack()
    BoutonA6=Button(fenA6, text="Quitter le jeu", command=fen.destroy)
    BoutonA6.pack()

def testA6():
    global s6
    global c6
    global fenA6

    v6 = int(s6.get())
    if v6 == c6 :
        fenA6.destroy()
        blaA6()
        
    else :
        tex = Label(fenA6, text="Réessaye", fg="white", bg="black")
        tex.pack()



#----------------------------------------------------------------------------------------------------------------------------------------------------------
def window2():
    global s7
    global c7
    global fen7
    fen7 = Tk()
    import random
    a7 = random.randint (50,100)
    b7 = random.randint (0,50)
    c7 = a7-b7
    tex = Label(fen7, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fen7, text=a7, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen7, text="-", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen7, text=b7, fg="white", bg="black")
    tex2.pack() 
    print c7
    #MODIFIER LA MISE EN PAGE ULTERIEUREMENT
    

    s7 = Spinbox(fen7, from_=0, to=1000)
    s7.pack()
    Bouton7=Button(fen7, text="Proposer", command=test)
    Bouton7.pack()
def test():
    global s7
    global c7
    global fen7
    # Récupère la valeur de S et de C des autres fonctions
    v = int(s7.get())
    
    if v == c7 :
        soustraction()
        fen7.destroy()
    
    else :
        tex5 = Label(fen7, text="Réessaye", fg="white", bg="black")
        tex5.pack()

#-----------------------------------------------------------------------------------------------------------------------------------------------------------

def soustraction():
    global s8
    global c8
    global fen8
    fen8 = Tk()
    import random
    a8 = random.randint (50,100)
    b8 = random.randint (0,50)
    c8 = a8-b8
    tex = Label(fen8, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fen8, text=a8, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen8, text="-", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen8, text=b8, fg="white", bg="black")
    tex2.pack() 
    print c8

    s8 = Spinbox(fen8, from_=0, to=1000)
    s8.pack()
    Bouton7=Button(fen8, text="Proposer", command=test)
    Bouton7.pack()
def test():
    global s8
    global c8
    global fen8
    # Récupère la valeur de S et de C des autres fonctions
    v = int(s8.get())
    
    if v == c8 :
        soustraction2()
        fen8.destroy()
    
    else :
        tex5 = Label(fen8, text="Réessaye", fg="white", bg="black")
        tex5.pack()

#-----------------------------------------------------------------------------------------------------------------------------------------------------------
def soustraction2():
    global s9
    global c9
    global fen9
    fen9 = Tk()
    import random
    a9 = random.randint (100,200)
    b9 = random.randint (0,100)
    c9 = a9-b9
    tex = Label(fen9, text="Combien font :", fg="white", bg="black")
    tex.pack()
    tex2 = Label(fen9, text=a9, fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen9, text="-", fg="white", bg="black")
    tex2.pack()
    tex2 = Label(fen9, text=b9, fg="white", bg="black")
    tex2.pack() 
    print c9

    s9 = Spinbox(fen9, from_=0, to=1000)
    s9.pack()
    Bouton7=Button(fen9, text="Proposer", command=test2)
    Bouton7.pack()
def test2():
    global s9
    global c9
    global fen9
    # Récupère la valeur de S et de C des autres fonctions
    v = int(s9.get())
    
    if v == c9 :
        soustraction2()
        fen9.destroy()
    
    else :
        tex5 = Label(fen8, text="Réessaye", fg="white", bg="black")
        tex5.pack()


#-----------------------------------------------------------------------------------------------------------------------------------------------------------

        
def window3():#<=== défini la window 3
    fen3 = Tk()
def window4():
    fen4 = Tk()
def window5():
    fen5 = Tk()

    
bouton=Button(fen, text="Les additions", command=window) #<== Créé un bouton permettant d'ouvrir la fenetre
bouton.pack()
bouton2=Button(fen, text="Les soustractions", command=window2)
bouton2.pack()
bouton3=Button(fen, text="Les divisions", command=window3)
bouton3.pack()
bouton4=Button(fen, text="Les multiplications", command=window4)
bouton4.pack()
bouton5=Button(fen, text="Un mélange de tout !", command=window5)
bouton5.pack()
bouton6=Button(fen, text="Quitter le jeu", command=fen.destroy)
bouton6.pack()


    


fen.mainloop()#<==Ouvre la fenetre
    
Sous forums
  • Aide à l'achat Mac
  • Création de Jeux
  • Linux
  • Création de sites web
  • Programmation
  • Internet
  • Steam Deck
  • Macintosh
  • Hardware
La vidéo du moment