在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()
答案 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")