Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problème command
#1
Bonjour à tous,

J'ai un petit soucis concernant mon programme.
Quand j'appelle directement la fonction 'louer-materiel', il m'affiche le numéro rentrer dans 'Entry'
mais quand je passa d'abord par la fonction 'acceuil' qui va ensuite dans 'louer_materiel', rien ne s'imprime. J'ai l'impression qu'il a oublié 'saisir'

Seriez-vous pourquoi cela ne marche pas ?
merci d'avance
Bonne journée
from tkinter import *

def louer_materiel():

    def louer(event):

        valeur=saisir.get()
        print(str(valeur))



    fenetre1 = Tk()

    saisir=StringVar()

    entree = Entry(fenetre1,textvariable=saisir, width=30).grid(row=2, column=2,columnspan=2,pady=8)
    bouton_valider  = Button(fenetre1, text="ok", command=louer,width=10,heigh=1).grid(row=3,column=2,padx=20, pady=8)
    fenetre1.mainloop()

def acceuil ():

    fenetre = Tk()
    bouton1 = Button(fenetre, text="Louer un matériel",width=36,heigh=1,command=louer_materiel).grid(row=2,column=1,padx=20, pady=8)
    fenetre.mainloop()

acceuil()
Reply
#2
In this forum, users live in many different places around the world, but everybody agrees on the use of english as a common language, so please try to write your future posts in english. I know it can be difficult but there are online translation tools that can help you with this.

Concerning the code, usually one uses a single Tk instance at a time in tkinter, so if you want to create several toplevel windows, use instances of the Toplevel class instead. Also mainloop() is normally called on a single window. I changed a few things in the code to make it work.

from tkinter import *
 
def louer_materiel():
 
    def louer():
 
        valeur=saisir.get()
        print(str(valeur))
        fenetre1.destroy()
 
 
 
    fenetre1 = Toplevel()
 
    saisir=StringVar()
 
    entree = Entry(fenetre1,textvariable=saisir, width=30).grid(row=2, column=2,columnspan=2,pady=8)
    bouton_valider  = Button(fenetre1, text="ok", command=louer,width=10,heigh=1).grid(row=3,column=2,padx=20, pady=8)

 
def acceuil ():
 
    fenetre = Tk()
    bouton1 = Button(fenetre, text="Louer un matériel",width=36,heigh=1,command=louer_materiel).grid(row=2,column=1,padx=20, pady=8)
    fenetre.mainloop()
 
acceuil()
Reply
#3
Thank you very much for your answer !
Have a nice day
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  petit problème python salahoum 1 758 Jan-21-2019, 11:37 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020