0

I want to change the layout of Label when we exit the entry widget.

For Eg: a. In the Layout state 1, The first label says "Entry all the names you want" and beside it you have an entry widget to get the details of names. Format is like number of names, name details. Eg: 2,dan,brown.

enter image description here

b. Below the first label, you have the second label named "Choose the config for" and beside it you have a drop-down menu window.

BUT, c. I wanted to change the label layout to "Choose the config for dan" based on the details entered in the 1st Entry window dynamically.

SO wanted to know if there is any function that we can call at the "EXIT" of the entry widget which can go and modify/re-create the Label 2 layout based on the info provided in the Entry 1 and change the layout to "Layout State 2".

Update: I tried the below code with bind and FocusOut, but its not doing what is doing as I was expecting.

#!/usr/intel/bin/python2.7

import Tkinter
import Tkinter as tk
from Tkinter import * 
import ttk
import Tkinter
from Tkinter import *
import subprocess
import shlex
import os 
#from PIL import Image, ImageTk
#import Image, ImageTk
import time
import string
import tkFont
import ttk

global aloha_blue_frame_loop
aloha_blue_frame_loop = 1

class MyApp:
    def __init__(self, parent):
        self.rel3 = None
        self.rel4 = None
        self.rel5 = None
        self.reo1 = None
        self.ree3 = None
        self.ree4 = None
        self.ree5 = None
        self.aloha_frame = None
        self.aloha_name = None
        self.aloha_type = None
        self.aloha_name_e = [] 
        self.aloha_type_e = [] 
        self.aloha_choose_int_list = {}
        self.aloha_choose_int_val = StringVar()

    if not (self.rel4):
        self.rel4 = Label(root, font=MyFontH2, text="Enter All the Names You Want: ")
        self.rel4.grid(row=0, column=0, sticky='W')
        self.rel4.rowconfigure(0,weight=1)
    else:
        self.rel4.grid()

    if not (self.ree4):
        self.ree4 = Entry(self.aloha_frame, font=MyFontH2)
        self.ree4.grid(row=0, column=1)
        self.ree4.rowconfigure(0,weight=1)
        self.ree4.delete(0, END)
        self.ree4.insert(0, '')
        self.ree4.bind('<FocusOut>', self.ree4_entry_click)
    else:
        self.ree4.grid()

    if not (self.rel5):
        self.rel5 = Label(root, font=MyFontH2, text="Enter the details for student: ")
        self.rel5.grid(row=1, column=0, sticky='W')
        self.rel5.rowconfigure(1,weight=1)
    else:
        self.rel5.grid()

    if not (self.ree5):
        self.ree5 = Entry(self.aloha_frame, font=MyFontH2)
        self.ree5.grid(row=1, column=1)
        self.ree5.rowconfigure(1,weight=1)
    else:
        self.ree5.grid()

def ree4_entry_click(self, *args):
  entry_values_l = (self.ree4.get()).split(",")
  print "values of entry_values_l", entry_values_l
  if (self.rel5):
        self.rel5.grid_forget()
        self.rel5 = None 

  if not (self.rel5):
      self.rel5 = Label(root, font=MyFontH2, text="Enter the details for %s student:"%(entry_values_l[1]))
      self.rel5.grid(row=1, column=0, sticky='W')
      self.rel5.rowconfigure(1,weight=1)
  else:
      self.rel5.grid()

root = Tk()
root.title("Test UI")

MyFontH2 = tkFont.Font(family='courier', size=20, weight=tkFont.BOLD)

myapp = MyApp(root)
root.mainloop()

I was expecting that, the Focusout will call the binded function, take the required value from the entry widget and edit/change the value of the 2nd the label, but its not doing so. Am i making any mistake here ?

Desperado
  • 105
  • 9

1 Answers1

2

Try:

widget.bind('<FocusOut>', callback_handler)
figbeam
  • 7,001
  • 2
  • 12
  • 18
  • This triggers every time the mouse leaves the widget area, not if the focus changes. – Joshua Nixon Aug 12 '18 at 19:25
  • My bad. Changed the answer to FocusOut which should work better. – figbeam Aug 12 '18 at 19:59
  • @figbeam: Thanks a lot for the response. I tried using in the above sample code, but its not working as expected. Am i making any mistake in the code ? – Desperado Aug 12 '18 at 22:24
  • @figbeam: Think i got it fixed.. Forgot to assign None value to the widget after forgetting it.. Hope this is fine. Will try it out in my logic. Thanks a lot for the help. – Desperado Aug 13 '18 at 00:25