sel1=tk.IntVar() # string variable
sel1.set(0)
data=[5,3,15,22]
cb1 = ttk.Combobox(my_w, values=data,height=3, width=5,
font=22, textvariable=sel1)
cb1.grid(row=0,column=0,padx=10,pady=30)
b1=tk.Button(my_w,text='Sum',command=lambda:my_upd(),font=22)
def my_upd(*args):
total=sel1.get() + int(t1.get("1.0",END))
l1.config(text=total)# update the Label text
import tkinter as tk
from tkinter import ttk
from tkinter import *
my_w = tk.Tk()
my_w.geometry("400x250") # Size of the window
my_w.title("www.plus2net.com") # Adding a title
def my_upd(*args):
total=sel1.get() + int(t1.get("1.0",END))
l1.config(text=total) # update the Label text
sel1=tk.IntVar() # string variable
sel1.set(0)
data=[5,3,15,22]
cb1 = ttk.Combobox(my_w, values=data,height=3,
width=5,font=22, textvariable=sel1)
cb1.grid(row=0,column=0,padx=10,pady=10)
t1=tk.Text(my_w,width=10,height=1,bg='yellow',font=22)
t1.grid(row=0,column=1,padx=5)
t1.insert(tk.END, 0) # initial value of text widget
l1=tk.Label(my_w,text='Total',font=22,fg='blue')
l1.grid(row=0,column=2,padx=5)
b1=tk.Button(my_w,text='Sum',command=lambda:my_upd(),font=22)
b1.grid(row=1,column=1)
#sel1.trace('w',my_upd) # to trigger the function on change
my_w.mainloop() # Keep the window open
Combobox 29-07-2022 | |
Dear Sir, Thank you for your good instructions. I learn a lot from your videos. One question: how to delete the combobox option dynamicly? i was unable to use cb1['values'] -=(e1.get(),) to delete the option. please kindly teach me how to do it. Thank you very much. I subcribed your yourtube already. ST |
05-08-2022 | |
You can't delete by using cb1['values'] -=(e1.get(),) as it is a tuple. Create a new tuple with all the options except the one you want to delete. Then assign the new tuple to cb1. This part is added to this page. Here is the video again. https://youtu.be/PICzrYI6O9A |
22-11-2022 | |
In one of the programs which i am working , the combo box freezes when i click on dropdown and then the application stops and crashes. Please advise |
08-01-2023 | |
Are you using any onclick event and triggering any function? Just remove the function and see how it is working. Then check the code inside the function. |