Привет, ребята. Мне нужна помощь с моим GUI. Я хочу вставить элемент в один вид дерева и одновременно обновить другой вид дерева и вставить номер в запись. Проблема заключается в том, что первое древовидное представление создается в другом классе, нежели второе дерево и поле ввода. Приведенный ниже код является краткой версией из текущей. Я ценю помощь и терпение с новыми программистами, как я. Заранее спасибо.
class store(Page):
def __init__(self, parent, *args, **kwargs):
Page.__init__(self, parent, *args, **kwargs)
self.parent=parent
frame2 = tk.Frame(self, width=500, height=500, bd = 2, relief=tk.GROOVE)
frame2.pack(side="top", fill="both", expand=True)
###
self.label = tk.Label(frame2, text="Inventario", font="Helvetica 18 bold", justify="center")
self.label.pack(side="top", pady=10, fill="x", anchor=tk.E)
###
frame_b=tk.Frame(frame2, bd = 2, relief=tk.GROOVE)
frame_b.pack(side="right", anchor=tk.N+tk.W)
##
frame_in=tk.Frame(frame2, bd = 2, relief=tk.GROOVE)
frame_in.pack(side="right", anchor=tk.N+tk.W, padx=5)
#
self.tree=ttk.Treeview(frame_in, columns=("Product", "Unitari Cost ($/Kg)", "Date"), height=20)
self.tree.heading('#0', text='#')
self.tree.heading('#1', text="Product")
self.tree.heading('#2', text="Unitari Cost ($/Kg)")
self.tree.heading('#3', text="Date")
self.tree.column('#0', stretch=0, width=50, anchor=tk.W)
self.tree.column('#1', stretch=0, width=400, anchor=tk.N)
self.tree.column('#2', stretch=0, width=200, anchor=tk.N)
self.tree.column('#3', stretch=0, width=200, anchor=tk.N)
self.tree.grid(row=0, column=0, sticky=tk.NSEW)
#
self.ysb = ttk.Scrollbar(frame_in, orient=tk.VERTICAL, command=self.tree.yview)
self.tree['yscroll'] = self.ysb.set
self.ysb.grid(in_=frame_in, row=0, column=1, sticky=tk.NS)
obj = general_production()
#
def new_item():
self.tree.insert("", "end", text= 1, values=("Bread", "2355.23", "12/02/2020"))
obj.up_date_production()
##
b_new = tk.Button(frame_b, text="New", width = 10, command=new_item)
b_new.pack(pady=5, padx= 5)
class general_production(Page):
def __init__(self, parent, *args, **kwargs):
Page.__init__(self, parent, *args, **kwargs)
self.parent=parent
frame2 = tk.Frame(self, width=500, height=500, bd = 2, relief=tk.GROOVE)
frame2.pack(side="top", fill="both", expand=True)
####
label = tk.Label(frame2, text="Formulas", font="Helvetica 18 bold", justify="center")
label.pack(side="top", pady=10, fill="x", anchor=tk.E)
###
frame_b=tk.Frame(frame2, bd = 2, relief=tk.GROOVE)
frame_b.pack(side="right", anchor=tk.N+tk.W)
###
frame_f=tk.Frame(frame2, bd = 2, relief=tk.GROOVE)
frame_f.pack(side="right", anchor=tk.N+tk.W, padx=5)
##
self.tree=ttk.Treeview(frame_f, columns=("#1", "#2"), height=20)
self.tree.heading('#0', text='Product')
self.tree.heading('#1', text="Unitari Cost ($/Kg)")
self.tree.heading('#2', text="Production per day (Kg/day)")
self.tree.column('#0', stretch=0, width=250)
self.tree.column('#1', stretch=0, width=100, anchor=tk.N)
self.tree.column('#2', stretch=0, width=150, anchor=tk.N)
self.tree.grid(row=0, column=0, sticky=tk.NSEW)
#
self.ysb = ttk.Scrollbar(frame_f, orient=tk.VERTICAL, command=self.tree.yview)
self.tree['yscroll'] = self.ysb.set
self.ysb.grid(in_=frame_f, row=0, column=1, sticky=tk.NS)
#
self.n_recipies =tk.StringVar()
entrie =tk.Entry(frame2, width = 20, textvariable =self.n_recipies, state='readonly', readonlybackground ="white")
entrie.pack(side="right", anchor=tk.N+tk.W)
def up_date_production(self):
self.treeview.insert("", "end", text= "Bread", values=("2355.23", "987"))
self.n_recipies.set(1)