如何在禁用条目时在tkinter条目窗口小部件中插入值

时间:2018-04-05 13:43:09

标签: python tkinter treeview

tkinter entry被禁用的同时尝试在widget中插入值。我希望实现entry widget中不能删除的值。已经检查过此网站以查找类似的问题要解决这个问题,但无法找到。

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()

1 个答案:

答案 0 :(得分:3)

我找到了一种方法来实现这一点,之后使用entry启用config然后我disable

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")