Python Forum
Problème command - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problème command (/thread-24320.html)



Problème command - paulo - Feb-08-2020

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()



RE: Problème command - Gribouillis - Feb-08-2020

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()



RE: Problème command - paulo - Feb-09-2020

Thank you very much for your answer !
Have a nice day