Number of Text box based selection of Combobox

Tkinter Projects in Tkinter

Number of textbox based on Combobox selection

User has to select one of the two available options of the Combobox.
Based on the selection either two or three text boxes are to be displayed.

Based on Selection of option from Combobox display two or three text boxes in Tkinter window
import tkinter as tk
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x150")  # Size of the window 
my_w.title("")  # Adding a title
sel=tk.StringVar() # string variable 
my_opts=['Show Two','Show Three'] # options
cb1 = ttk.Combobox(my_w, values=my_opts,width=25,
        textvariable=sel,font=font1) # Combobox
cb1.grid(row=0,column=0,padx=10,pady=20,columnspan=3) # adding to grid
def my_upd(*args):
    for w in my_w.grid_slaves(1): # all elements 
        w.grid_remove()                  # delete elements 
    if(sel.get()=='Show Two'):
        t1 = tk.Text(my_w,  height=1, width=8,bg='yellow') # 
        t2 = tk.Text(my_w,  height=1, width=8,bg='yellow') # 
    elif(sel.get()=='Show Three'):
        t1 = tk.Text(my_w,  height=1, width=8,bg='yellow') # 
        t2 = tk.Text(my_w,  height=1, width=8,bg='yellow') # 
        t3 = tk.Text(my_w,  height=1, width=8,bg='yellow') # 
sel.trace('w',my_upd) # on change of string variable 
my_w.mainloop()  # Keep the window open
Python Tkinter Projects
Tkinter Text Tkinter Entry How to Validate user entered data
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer