Jul-29-2018, 04:45 PM
Hello everybody!
I am a beginner in python. I start to access the basics...
Thank you for this very useful site and for the time you spend to answer beginners like me :-)
I created a program* in which (without setting anything) the "tab" key lets move from one field to another. When the focus comes on the button "Validar", I would like to only press "Enter" key to press the button, but it does not work... I have to "Click" with the mouse...
How to do that?
Thank you !
* It can only multiply two numbers for the moment...
Here is te code:
I am a beginner in python. I start to access the basics...
Thank you for this very useful site and for the time you spend to answer beginners like me :-)
I created a program* in which (without setting anything) the "tab" key lets move from one field to another. When the focus comes on the button "Validar", I would like to only press "Enter" key to press the button, but it does not work... I have to "Click" with the mouse...
How to do that?
Thank you !
* It can only multiply two numbers for the moment...

Here is te code:
#!/usr/bin/python3.7 # -*- coding: utf-8 -*- # Premières lignes = shebang : à étudier !!! # http://www.chicoree.fr/w/Rendre_un_script_ex%C3%A9cutable # Utilisation de la méthode "place()" pour organiser l'interface # http://www.xavierdupre.fr/app/teachpyx/helpsphinx/c_gui/tkinter.html#disposition-des-objets-dans-une-fenetre from tkinter import * # Création de la fenêtre fenetre = Tk() # Définir la taille de la fenêtre fenetre.geometry("240x165") fenetre.title("¡Laurent Multiplica!") # Création de la fonction qui sera appelée par le bouton def valider(): a1 = entry_a1.get() print ("Su numero a1 es: "+ a1) a2 = entry_a2.get() print ("Su numero a1 es: "+ a2) c = int(a1)*int(a2) print ("a1 x a2 vale:", c) # Création d'une zone de texte de type "Label" resultat = Label(fenetre, text=" a1 x a2 = " + str(c) + " ", bg='#6EC86E', font = ('Helvetica', '13')) resultat.place(x=100, y=80) # Création d'une zone de texte de type "Label" Pour le titre titre = Label(fenetre, text=" Pequeña aplicación ", bg='white', font = ('Helvetica', '16') ) titre.pack() # Création d'une zone de texte de type "Label" Pour le titre sous_titre = Label(fenetre, text="Cálculo de a1 x a2", bg='white', font = ('Helvetica', '13') ) sous_titre.pack() # Création d'une zone de texte de type "Label" pour a1 label_a1 = Label(fenetre, text="a1 :") label_a1.place(x=10, y=60) # Création d'un champ de saisie de type "Entry" pour a1 entry_a1 = Entry(fenetre, width=5) # entry_a1.insert(0, "a1 ?") entry_a1.place(x=40, y=60) # Création d'une zone de texte de type "Label" pour a2 label_a2 = Label(fenetre, text="a2 :") label_a2.place(x=10, y=90) # Création d'un champ de saisie de type "Entry" pour a2 entry_a2 = Entry(fenetre, width=5) # entry_a2.insert(0, "a2 ?") entry_a2.place(x=40, y=90) # Création d'un Button monBouton = Button(fenetre, text="Validar", command=valider) monBouton.place(x=10, y=120) # Affichage du Button dans la fenêtre