Reordering the tabbing order in tkinter

Solved
Baldo35 Posted messages 14 Status Membre -  
Baldo35 Posted messages 14 Status Membre -
Hello everyone,
in the series: it is in searching that we progress, I am trying to change the order of tabulations in Tkinter.
In my code:
#-------------------------------------------------------------------------------
# Name: FrancsEuros.py
# Purpose: An easy conversion from Francs to Euros or Euros to Francs
#
# Author: BALDONI GUY
#
# Created: 07/09/2020
# Copyright: (c) BALDONI GUY 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
# coding: utf8
from tkinter import *
import tkinter.messagebox
from PIL import ImageTk, Image
import pygame
import os
import winsound
from time import *
from time import gmtime, strftime, sleep
import locale
import time
import datetime
from math import *
from winsound import *

# For the date in French
locale.setlocale(locale.LC_TIME,'')

# Definition of frequency and duration of winsound beeps
frequency = 2500 # Set Frequency To 2500 Hertz
duration = 500 # Set Duration To 500 ms == 1/2 second

# Definition of struck and non-struck fonts
fontbarre = "-family {DejaVu Sans} -size 8 -weight normal -underline 0 -overstrike 1"
fontnormal = "-family {DejaVu Sans} -size 8 -weight normal -underline 0 -overstrike 0"

def touche_clav(event):
btn_effacer["state"] = "normal"

def touche_tabulation(event):
print('You pressed the tab key')
print(root.focus_get())
print(Francs.focus_get())
if Francs.focus_get() == '.!button2' :
print('Focus on Button2')

#*******************************************************************************
# MUSIC
# Function for choice with or without music
def choix_musique():
global compteur
if btn_couperMusique['font'] == fontbarre:
btn_couperMusique['font'] = fontnormal
couper_musique()
else:
btn_couperMusique['font'] = fontbarre
jouer_musique('oiseau.wav')
compteur = 0

# We play some music
def jouer_musique(nom_musique):
pygame.mixer.init()
pygame.mixer.music.load(nom_musique)
pygame.mixer.music.play()

# Function to stop music
def couper_musique():
pygame.mixer.music.stop()
#*******************************************************************************

#*******************************************************************************
# Function to destroy the main window following a keyboard event
def exit(event):
root.destroy()

#*******************************************************************************

#*******************************************************************************
# Function to choose between Francs->Euros or Euros->Francs
def switch_feef():
# We clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
if btn_ch_mode["text"] == "Francs -> Euros" :
btn_ch_mode["text"] = "Euros -> Francs"
root.title("Current conversion Francs->Euros")
Francs.focus_set()
else:
btn_ch_mode["text"] = "Francs -> Euros"
root.title("Current conversion Euros->Francs")
Euros.focus_set()
btn_effacer["state"] = "disabled"

#*******************************************************************************

#*******************************************************************************
# We perform the conversion
def convert(event):
# If Francs and Euros are filled and we are in Francs -> Euros mode
# the user wants to make another calculation then we redo the calculation
if ((Francs.get() != "") and (Euros.get() != "")) and btn_ch_mode["text"] == "Euros -> Francs":
try :
tmp = float(Francs.get()) * 0.1524
except :
tkinter.messagebox.showerror('Francs', '( ' + Francs.get() +' )' + ' is not a correct amount')
Francs.insert(0, 'Incorrect input')
winsound.Beep(frequency, duration)
btn_effacer["state"] = "normal"
effacer()
else :
round = float("%0.2f" % tmp)
strround = str(round)
Euros.delete(0 , END)
Euros.insert(0, strround + ' €')
# If Francs and Euros are filled and we are in Euros -> Francs mode
# the user wants to make another calculation then we redo the calculation
elif ((Francs.get() != "") and (Euros.get() != "")) and btn_ch_mode["text"] == "Francs -> Euros":
try :
tmp = float(Euros.get()) * 6.5596
except :
tkinter.messagebox.showerror('Euros', '( ' + Euros.get() +' )' + ' is not a correct amount')
winsound.Beep(frequency, duration)
btn_effacer["state"] = "normal"
effacer()
Euros.insert(0, 'Incorrect input')
else :
round = float("%0.2f" % tmp)
strround = str(round)
Francs.delete(0 , END)
Francs.insert(0, strround + ' F')
# Otherwise normal operation
else :
x = Francs.get()
y = Euros.get()
# If Francs and Euros are empty the Clear button is grayed out
if (x == "") and (y == ""):
btn_effacer["state"] = "disabled"
else:
btn_effacer["state"] = "normal"

if (x != "" ) and (y == ""):
# Check the correct input of Francs
try :
tmp = float(x) * 0.1524
except :
# We clear the Francs field and display the error
Francs.delete(0 , END)
Francs.insert(0, 'Incorrect input')
winsound.Beep(frequency, duration)
tkinter.messagebox.showerror('Francs', '( ' + x +' )' + ' is not a correct amount')
else :
# It's good then we display the result
round = float("%0.2f" % tmp)
strround = str(round)
Euros.delete(0 , END)
Euros.insert(0, strround + ' €')
Francs.focus_set()
elif (y != "") and (x == ""):
# Check the correct input of Euros
try :
tmp = float(y) * 6.5596
except :
# We clear the Euros field and display the error
Euros.delete(0 , END)
Euros.insert(0, 'Incorrect input')
winsound.Beep(frequency, duration)
tkinter.messagebox.showerror('Euros', '( ' + y +' )' + ' is not a correct amount')
else :
# It's good then we display the result
round = float("%0.2f" % tmp)
strround = str(round)
Francs.delete(0 , END)
Francs.insert(0, strround + ' F')
Euros.focus_set()

#*******************************************************************************

#*******************************************************************************
# Clear both input fields and disable the Clear button
def effacer():
# We clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
# The Clear button is grayed out
btn_effacer["state"] = "disabled"
# The cursor blinks in the Francs field
Francs.focus_set()
root.title("Current conversion Francs->Euros")

#*******************************************************************************
# Display an About window
def aff_infos(e) :
btn_effacer["state"] = "normal"
feninf = Toplevel()
feninf.config(bg='lightblue')
geo1=root.winfo_geometry()
geox=root.winfo_rootx()
geoy=root.winfo_rooty()
feninf.geometry("300x260+"+str(geox-50)+"+"+str(geoy-22))
feninf.title("About FrancsEuros")
feninf.resizable(height = False, width = False)
labinf=Label(feninf, bg='lightblue',fg='black',width=50,font=('Arial', 9),
text= "\nFrancseuros v1.0\n\n"
"Program written in Python / Tkinter\n"
"and distributed under the GNU GPL license.\n\n"
"© 2020 Guy Baldoni\n"
"( )\n\n"
"This program offers an easy conversion \n"
"Francs Euros or Euros Francs! \n"
"\n"
" ")
labinf.pack(pady=5)
bouf3=Button(feninf, text="Close", command=feninf.destroy, fg='blue', relief=RAISED)
bouf3.pack(side=BOTTOM,pady=10)
feninf.grab_set()
feninf.wait_window()
#*******************************************************************************

# Main window
root = Tk()
root.geometry("430x160")

#*******************************************************************************
# Display the current date updated constantly
global compteur
compteur = 0
text = StringVar()
heure_syst = Label(root,fg = 'blue',textvariable = text)
heure_syst.pack(side = TOP)

def majheure():
if ((Francs.get() == "") and (Euros.get() == "")):
btn_effacer["state"] = "disabled"
# If the cursor blinks in the Francs field consistent update
if str(root.focus_get()) == '.!entry' :
btn_ch_mode["text"] = "Euros -> Francs"
root.title("Current conversion Francs->Euros")
# If the cursor blinks in the Euros field consistent update
elif str(root.focus_get()) == '.!entry2' :
btn_ch_mode["text"] = "Francs -> Euros"
root.title("Current conversion Euros->Francs")
Euros.focus_set()
global compteur
if btn_couperMusique['font'] == fontbarre:
compteur = compteur + 1
if btn_couperMusique['font'] == fontbarre and compteur > 540:
btn_couperMusique['font'] = fontnormal
compteur = 0
# Command that calls the majheure function after 300ms
time.sleep(0.3)
root.after(50,majheure)
text.set(time.strftime("%A %d %B %Y %H:%M:%S"))
root.after(50, majheure)
#*******************************************************************************

jouer_musique('oiseau.wav')

# Display a small logo in the window
img = ImageTk.PhotoImage(Image.open('h.gif'))
panel = Label(root, image = img)
panel.place(x = 10, y = 10)
# Testing color changes
#root.configure(bg='cyan')
# Places the application in the center of the screen
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
root.geometry("+%d+%d" % (x, y))
# Definition of the application title at the start
root.title("Current conversion Francs->Euros")
# Prevent resizing of the window
root.resizable(height = False, width = False)
root.event_delete
root.size()
#*******************************************************************************

#*******************************************************************************
# Buttons, labels and entry fields
#*******************************************************************************
#*******************************************************************************
# Button to stop the music
btn_couperMusique = Button(root, text="Songs", fg ='blue', command = choix_musique, relief=RAISED)
btn_couperMusique.place(x = 20, y = 125)
btn_couperMusique['font'] = fontbarre
#*******************************************************************************

#*******************************************************************************
# Button to switch the Francs->Euros or Euros->Francs conversion and its label
mode = Label(root,text="Mode Selection ->")
mode.place(x = 230, y = 30)
btn_ch_mode = Button(root, text="Euros -> Francs", fg ='blue', command = switch_feef , relief = RAISED)
btn_ch_mode.place ( x = 330, y = 25)
#*******************************************************************************

#*******************************************************************************
# Input field for Francs
lblFrancs = Label(root,text="Amount in Francs: ")
lblFrancs.place(x = 110, y = 20)
Francs = Entry(root, width = 15)
Francs.place( x = 120, y = 40)
# The cursor blinks in the Francs field
Francs.focus_set()
#*******************************************************************************

#*******************************************************************************
# Input field for Euros
lblEuros = Label(root,text="Amount in Euros: ")
Euros = Entry(root, width = 15 )
lblEuros.place(x = 110, y = 60)
Euros.place(x = 120, y = 80)
#*******************************************************************************

#*******************************************************************************
# The Clear button is created
btn_effacer = Button(root, text="Clear", fg ='blue', command = effacer, relief = RAISED)
btn_effacer.place(x = 230, y = 60)
# By default the Clear button is grayed out because there is nothing to clear
btn_effacer["state"] = "disabled"

#*******************************************************************************

#*******************************************************************************
# The Quit button is created
bouton2 = Button(root, text="Quit", fg ='blue', command = root.destroy, relief = RAISED)
bouton2.place(x = 375, y = 130)
#*******************************************************************************

#*******************************************************************************
# Label for instructions
modeEmploi = Label(root,text="Enter to calculate,\nQ or Escape to quit\n H--> About...")
modeEmploi.place( x = 100, y = 100)
#*******************************************************************************
#*******************************************************************************

#*******************************************************************************

# Detection of any key on the keyboard, Enter, Escape or Q key
root.bind('<Tab>', touche_tabulation)
root.bind('<Key>', touche_clav)
root.bind('<Return>', convert)
root.bind("<Escape>", exit)
root.bind("q", exit)
root.bind("Q", exit)
root.bind('h',aff_infos)
root.bind('H',aff_infos)
root.mainloop()
# When quitting the program, we stop the music and say goodbye

couper_musique()
jouer_musique('aurevoir.wav')
#*******************************************************************************
#*******************************************************************************
#*******************************************************************************

at lines 40 to 45 in the function <touche_tabulation>, I would like to reassign the focus but the <if> in line 44 is never true.
Additionally, I tried to change the focus assignment in the same function and it doesn't work.
Can you help me solve this puzzle?
Thank you in advance.

7 réponses

yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 587
 
Hello, could you specify "python" in the code tags when you share Python, as explained: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Furthermore, it will be easier for us to help you if you simplify your program, keeping only the part related to the tkinter tabs.
0
Baldo35 Posted messages 14 Status Membre
 
Thank you very much for your effort yg_be.
Here is the cleaned Python 3.8.5 code :
#-------------------------------------------------------------------------------
# Name: FrancsEuros.py
# Purpose: Easy conversion Francs Euros or Euros Francs
#
# Author: BALDONI GUY
#
# Created: 07/09/2020
# Copyright: (c) BALDONI GUY 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
# coding: utf8
from tkinter import *
import tkinter.messagebox
import os
import winsound
import datetime
from math import *
from winsound import *

# Define winsound beep frequency and duration
frequency = 2500 # Set Frequency To 2500 Hertz
duration = 500 # Set Duration To 500 ms == 1/2 second

# Define a struck and non-struck font
fontbarre = "-family {DejaVu Sans} -size 8 -weight normal -underline 0 -overstrike 1"
fontnormal = "-family {DejaVu Sans} -size 8 -weight normal -underline 0 -overstrike 0"

def touche_clav(event):
btn_effacer["state"] = "normal"

def touche_tabulation(event):
print('You pressed the tab key')
print(root.focus_get())
print(Francs.focus_get())
if Francs.focus_get() == '.!button2' :
print('Focus on Button2')

#*******************************************************************************
# Function to destroy the main window after a keyboard event
def exit(event):
root.destroy()

#*******************************************************************************

#*******************************************************************************
# Function to choose a mode Francs->Euros or Euros->Francs
def switch_feef():
# Clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
if btn_ch_mode["text"] == "Francs -> Euros" :
btn_ch_mode["text"] = "Euros -> Francs"
root.title("Current conversion Francs->Euros")
Francs.focus_set()
else:
btn_ch_mode["text"] = "Francs -> Euros"
root.title("Current conversion Euros->Francs")
Euros.focus_set()
btn_effacer["state"] = "disabled"

#*******************************************************************************

#*******************************************************************************
# Clear both input fields and grey out the Clear button
def effacer():
# Clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
# The Clear button is greyed out
btn_effacer["state"] = "disabled"
# The cursor blinks in the Francs field
Francs.focus_set()
root.title("Current conversion Francs->Euros")

# Main window
root = Tk()
root.geometry("430x160")

# Test for coloring
#root.configure(bg='cyan')
# Center the application on the screen
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
root.geometry("+%d+%d" % (x, y))
# Define the title of the application at the start
root.title("Current conversion Francs->Euros")
# Prevent window resizing
root.resizable(height = False, width = False)
root.event_delete
root.size()
#*******************************************************************************

#*******************************************************************************
# Buttons, labels and input fields
#*******************************************************************************

#*******************************************************************************
# Conversion switch button Francs->Euros or Euros->Francs and its label
mode = Label(root,text="Mode selection ->")
mode.place(x = 230, y = 30)
btn_ch_mode = Button(root, text="Euros -> Francs", fg ='blue', command = switch_feef , relief = RAISED)
btn_ch_mode.place ( x = 330, y = 25)
#*******************************************************************************

#*******************************************************************************
# Francs input field
lblFrancs = Label(root,text="Amount in Francs : ")
lblFrancs.place(x = 110, y = 20)
Francs = Entry(root, width = 15)
Francs.place( x = 120, y = 40)
# The cursor blinks in the Francs field
Francs.focus_set()
#*******************************************************************************

#*******************************************************************************
# Euros input field
lblEuros = Label(root,text="Amount in Euros : ")
Euros = Entry(root, width = 15 )
lblEuros.place(x = 110, y = 60)
Euros.place(x = 120, y = 80)
#*******************************************************************************

#*******************************************************************************
# The Clear button is created
btn_effacer = Button(root, text="Clear", fg ='blue', command = effacer, relief = RAISED)
btn_effacer.place(x = 230, y = 60)
# By default the Clear button is greyed out as there is nothing to clear
btn_effacer["state"] = "disabled"

#*******************************************************************************

#*******************************************************************************
# The Quit button is created
bouton2 = Button(root, text="Quit", fg ='blue', command = root.destroy, relief = RAISED)
bouton2.place(x = 375, y = 130)
#*******************************************************************************

#*******************************************************************************
# Instruction label
modeEmploi = Label(root,text="Press Enter to calculate,\nQ or Escape to quit\n H--> About...")
modeEmploi.place( x = 100, y = 100)
#*******************************************************************************
#*******************************************************************************

#*******************************************************************************

# Detect any key press from the keyboard, Enter, Escape or Q
root.bind('<Tab>', touche_tabulation)
root.bind('<Key>', touche_clav)

root.bind("<Escape>", exit)
root.bind("q", exit)
root.bind("Q", exit)

root.mainloop()
# When exiting the program, stop the music and say goodbye

#*******************************************************************************
#*******************************************************************************
#*******************************************************************************


I am still interested in the function <touche_tabulation> which concerns me.
Thanks again to everyone who will respond.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 587
 
I repeat my request: can you specify "python" in the code tags when you share Python, as explained here: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
I didn't fully understand what you wanted to do. You don't explain the expected behavior or the behavior obtained.
This might work better:
if str(Francs.focus_get()) == '.!button2' :
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587
 
Moreover, the lift() function allows you to control the tab order.
0
Baldo35 Posted messages 14 Status Membre
 
Thank you yg_be for your patience, I am learning.
My code :
<code python>
#-------------------------------------------------------------------------------
# Name: FrancsEuros.py
# Purpose: An easy conversion from Francs to Euros or Euros to Francs
#
# Author: BALDONI GUY
#
# Created: 07/09/2020
# Copyright: (c) BALDONI GUY 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
# coding: utf8
from tkinter import *
import os
from math import *

def key_press(event):
btn_clear["state"] = "normal"

def tab_key(event):
print('You pressed the tab key')
print(root.focus_get())
if str(Francs.focus_get()) == '.!button2' :
print('Focus on Button2')

#*******************************************************************************
# Function to destroy the main window upon a keyboard event
def exit(event):
root.destroy()

#*******************************************************************************

#*******************************************************************************
# Function to switch between Francs->Euros or Euros->Francs mode
def switch_feef():
# Clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
if btn_switch_mode["text"] == "Francs -> Euros" :
btn_switch_mode["text"] = "Euros -> Francs"
root.title("Current conversion Francs->Euros")
Francs.focus_set()
else:
btn_switch_mode["text"] = "Francs -> Euros"
root.title("Current conversion Euros->Francs")
Euros.focus_set()
btn_clear["state"] = "disabled"

#*******************************************************************************

#*******************************************************************************
# Clears both input fields and disables the Clear button
def clear():
# Clear both input fields
Euros.delete(0 , END)
Francs.delete(0 , END)
# The Clear button is disabled
btn_clear["state"] = "disabled"
# The cursor blinks in the Francs field
Francs.focus_set()
root.title("Current conversion Francs->Euros")

# Main window
root = Tk()
root.geometry("430x160")

# Setting the title of the application initially
root.title("Current conversion Francs->Euros")
# Prevent resizing of the window
root.resizable(height = False, width = False)
root.event_delete
root.size()
#*******************************************************************************

#*******************************************************************************
# Buttons, labels and input fields
#*******************************************************************************

#*******************************************************************************
# Button to switch between Francs->Euros or Euros->Francs and its label
mode = Label(root,text="Mode selection ->")
mode.place(x = 230, y = 30)
btn_switch_mode = Button(root, text="Euros -> Francs", fg ='blue', command = switch_feef , relief = RAISED)
btn_switch_mode.place ( x = 330, y = 25)
#*******************************************************************************

#*******************************************************************************
# Input field for Francs
lblFrancs = Label(root,text="Amount in Francs : ")
lblFrancs.place(x = 110, y = 20)
Francs = Entry(root, width = 15)
Francs.place( x = 120, y = 40)
# The cursor blinks in the Francs field
Francs.focus_set()
#*******************************************************************************

#*******************************************************************************
# Input field for Euros
lblEuros = Label(root,text="Amount in Euros : ")
Euros = Entry(root, width = 15 )
lblEuros.place(x = 110, y = 60)
Euros.place(x = 120, y = 80)
#*******************************************************************************

#*******************************************************************************
# The Clear button is created disabled as there is nothing to clear
btn_clear = Button(root, text="Clear", fg ='blue', state = 'disabled',command = clear, relief = RAISED)
btn_clear.place(x = 230, y = 60)

#*******************************************************************************

#*******************************************************************************
# The Quit button is created
button2 = Button(root, text="Quit", fg ='blue', command = root.destroy, relief = RAISED)
button2.place(x = 375, y = 130)
#*******************************************************************************

#*******************************************************************************

# Detect any key press from the keyboard, including Enter, Escape or Q
root.bind('<Tab>', tab_key)
root.bind('<Key>', key_press)

root.bind("<Escape>", exit)
root.bind("q", exit)
root.bind("Q", exit)

root.mainloop()

#*******************************************************************************
#*******************************************************************************
#*******************************************************************************
</code>
In fact, when you repeatedly press tab, the focus moves through
the input fields and then on the buttons.
I would like to switch from one field to another without going through the buttons.
Thank you for your understanding.
Baldo35
0
Phil_1857 Posted messages 1883 Registration date   Status Membre Last intervention   169
 
Hello Baldo,

Still not!

It should look like this:
 # coding: utf8 from tkinter import * import os from math import * def key_press(event): btn_clear["state"] = "normal" def key_tab(event): print('You pressed the tab key') print(root.focus_get()) if str(Francs.focus_get()) == '.!button2' : print('Focus on Button2') 
0
Baldo35 Posted messages 14 Status Membre
 
Hello Phil,
the code you sent me works well but I would like:
Actually, when you press tab repeatedly, the focus goes through
the input fields and then to the buttons.
I would like to skip the buttons and go from one field to another.
Thank you for your understanding.
Baldo35
0
Phil_1857 Posted messages 1883 Registration date   Status Membre Last intervention   169
 
I didn't give you code that works well

I have provided the first 14 lines of your code with the code tags placed correctly

so that you can see exactly what it should look like

You need to put your complete code back with the tags; it must appear exactly

like in my example, with the colors, the indentations, and everything...
0
Baldo35 Posted messages 14 Status Membre
 
I'm sorry, Phil,
I'm trying:
#------------------------------------------------------------------------------- # Name: FrancsEuros.py # Purpose: An easy Francs to Euros or Euros to Francs conversion # # Author: BALDONI GUY # # Created: 07/09/2020 # Copyright: (c) BALDONI GUY 2020 # Licence: <your licence> #------------------------------------------------------------------------------- # coding: utf8 from tkinter import * import os from math import * def touche_clav(event): btn_effacer["state"] = "normal" def touche_tabulation(event): print('You pressed the tab key') print(root.focus_get()) if str(Francs.focus_get()) == '.!entry2' : print('Focus on Button3') Francs.focus_set() #******************************************************************************* # Function to destroy the main window due to a keyboard event def exit(event): root.destroy() #******************************************************************************* #******************************************************************************* # Function to choose a mode Francs->Euros or Euros->Francs def switch_feef(): # Clear both entry fields Euros.delete(0 , END) Francs.delete(0 , END) if btn_ch_mode["text"] == "Francs -> Euros" : btn_ch_mode["text"] = "Euros -> Francs" root.title("Current conversion Francs->Euros") Francs.focus_set() else: btn_ch_mode["text"] = "Francs -> Euros" root.title("Current conversion Euros->Francs") Euros.focus_set() btn_effacer["state"] = "disabled" #******************************************************************************* #******************************************************************************* # Clear both entry fields and disable the Clear button def effacer(): # Clear both entry fields Euros.delete(0 , END) Francs.delete(0 , END) # The Clear button is disabled btn_effacer["state"] = "disabled" # The cursor blinks in the Francs field Francs.focus_set() root.title("Current conversion Francs->Euros") # Main window root = Tk() root.geometry("430x160") # Set the title of the application at start root.title("Current conversion Francs->Euros") # Prevent resizing the window root.resizable(height = False, width = False) root.event_delete root.size() #******************************************************************************* #******************************************************************************* # Buttons, labels and entry fields #******************************************************************************* #******************************************************************************* # Button to switch conversion Francs->Euros or Euros->Francs and its label mode = Label(root,text="Mode selection ->") mode.place(x = 230, y = 30) btn_ch_mode = Button(root, text="Euros -> Francs", fg ='blue', command = switch_feef , relief = RAISED) btn_ch_mode.place ( x = 330, y = 25) #******************************************************************************* #******************************************************************************* # Entry field for Francs lblFrancs = Label(root,text="Amount in Francs : ") lblFrancs.place(x = 110, y = 20) Francs = Entry(root, width = 15) Francs.place( x = 120, y = 40) # The cursor blinks in the Francs field Francs.focus_set() #******************************************************************************* #******************************************************************************* # Entry field for Euros lblEuros = Label(root,text="Amount in Euros : ") Euros = Entry(root, width = 15 ) lblEuros.place(x = 110, y = 60) Euros.place(x = 120, y = 80) #******************************************************************************* #******************************************************************************* # The Clear button is created disabled because there is nothing to clear btn_effacer = Button(root, text="Clear", fg ='blue', state = 'disabled',command = effacer, relief = RAISED) btn_effacer.place(x = 230, y = 60) #******************************************************************************* #******************************************************************************* # The Quit button is created bouton2 = Button(root, text="Quit", fg ='blue', command = root.destroy, relief = RAISED) bouton2.place(x = 375, y = 130) #******************************************************************************* #******************************************************************************* # Detect any key press, Enter, Escape or Q key root.bind('<Tab>', touche_tabulation) root.bind('<Key>', touche_clav) root.bind("<Escape>", exit) root.bind("q", exit) root.bind("Q", exit) root.mainloop() #******************************************************************************* #******************************************************************************* #******************************************************************************* 

I hope this time it will be good.
So I would like the <Tab> key to switch from one entry field to another while avoiding going to
the buttons.
Thanks again for your patience.
Baldo35
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587 > Baldo35 Posted messages 14 Status Membre
 
do you still have the same problem with the if?
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587 > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
You first explained that you wanted to change the order of the tabulations.
Then you explain that you want to avoid going on the buttons.
What exactly is it about? Thank you for taking the time to explain clearly.

If you want to exclude the button widget button2 from the tab order:
button2.config(takefocus=False) 
0
Baldo35 Posted messages 14 Status Membre > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
Thank you very much to you yg_be, that's the solution I was waiting for.
I certainly expressed myself poorly but you understood me.
See you later on the web.
0
Baldo35 Posted messages 14 Status Membre
 
Hello,
the problem with the if has been resolved.
But I still can't force focus on my input field when tab is pressed (the focus inevitably goes to the buttons).
Thank you
0
Baldo35 Posted messages 14 Status Membre
 
On line 25, the :
 Francs.focus_set()

does not work.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587
 
We will be able to help you better if you quickly and spontaneously keep us informed of the effect of our suggestions.
0
Baldo35 Posted messages 14 Status Membre > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
Yes, indeed your solution applied to all button widgets causes the focus to remain on the input fields (that was the goal of my request).
0