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

programmation python

cd440
cd440
Niveau 7
26 novembre 2013 à 20:22:37

Bonjour, je débute dans la programmation python et je tente de faire une calculatrice qui permet de calculer du nombres. Je me trouve face à un problème concernant les 'StringVar()' car ces variables ne peuvent pas être prise comme des nombres. Donc j'ai essayé de contourner le problemes avec: nombre1=StrinVar()
i=nombre1_get()
mais cela ne fonctionne pas. voici mon programme intégrale (avec tkinter):

from tkinter import*

def fp():
global i
global j
global resultat
Label(fenetre,text="+").grid(row=2,column=0)
resultat=i+j

def fm():
global i
global j
global resultat
Label(fenetre,text="-").grid(row=2,column=0)
resultat=i-j

def ff():
global i
global j
global resultat
Label(fenetre,text="x").grid(row=2,column=0)
resultat=i*j

def fd():
global i
global j
global resultat
Label(fenetre,text="/").grid(row=2,column=0)
resultat=i/j

def ef():
global resultat
Label(fenetre,text=resultat).grid(row=5,column=1)

fenetre=Tk()
fenetre.title("calculatrice")
fenetre.geometry("170x210+400+150")

Label(fenetre,text=" ").grid(row=0,column=0)
Label(fenetre,text=" ").grid(row=6,column=0)
Label(fenetre,text=" ").grid(row=5,column=0)
Label(fenetre,text="___________________________").
grid(row=3,column=1)

nombre1=StringVar()
champ1=Entry(fenetre,textvariable=nombre1,bg="grey
")

i=nombre1.get()
champ1.grid(row=1,column=1)

nombre2=StringVar()
champ2=Entry(fenetre,textvariable=nombre2,bg="grey
")

j=nombre2.get()
champ2.grid(row=2,column=1)

plus=Button(fenetre,text="+",command=fp).grid(row=
18,column=0)

moins=Button(fenetre,text=" -",command=fm).grid(row=18,column=1)
foix=Button(fenetre,text=" x",command=ff).grid(row=19,column=0)
diviser=Button(fenetre,text=" /",command=fd).grid(row=19,column=1)
egale=Button(fenetre,text="=",command=ef).grid(row
=20,column=0)

fenetre.mainloop()

Hadesjeyjey
Hadesjeyjey
Niveau 9
26 novembre 2013 à 20:23:17

il y a un forum prog où tu seras mieux renseigné :ok:

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