Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert value in tkinter entry widget while entry is disabled

Am trying to insert value in tkinter entry while the widget is disabled.I want to achieve that for the value in the entry widget not to be deleted.Have checked this site to find similar question to address this but couldn't found any.

from tkinter import ttk
import tkinter as tk


blow = [("january", "2013")]


def func():
    for child in tree.get_children():
        sum =(tree.item(child, "values")[1])
        e1.delete(0, tk.END)
        e1.insert(0, sum)
        print(sum)


root = tk.Tk()
root.geometry("400x300")

tree = ttk.Treeview(columns=("columns1", "columns"), show="headings",
selectmode="browse")
tree.heading("#1", text="Month")
tree.heading("#2", text="Year")

for n in blow:
    tree.insert("", tk.END, values=(n))
tree.pack()

b1 = tk.Button(text="insert", command=func)
b1.pack()

e1 = tk.Entry()
e1.config(state="disable")
e1.pack()

root.mainloop()
like image 493
AD WAN Avatar asked Oct 28 '25 04:10

AD WAN


1 Answers

I found a way to do this need to enable the entry by using config after that then i disable it

def func():
    for child in tree.get_children():
        sum = (tree.item(child, "values")[1])
        e1.config(state="normal")
        e1.delete(0, tk.END)
        e1.insert(0, sum)
        print(sum)
        e1.config(state="disable")
like image 71
AD WAN Avatar answered Oct 29 '25 19:10

AD WAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!