我需要帮助来确定如何重建gtk.stack的元素。
假设孩子是一个包含可能必须以多种方式重建的信息的gtk.box,因为重建应该完成?
def refresh_take(self):
self.take_container.destroy()
#Reconstructed container
self.take_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#Reconstructed Top label
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
label = Gtk.Label("For take:", xalign=0)
self.take_container.pack_start(label, False, False, 10)
get_ready = self.database.get_tomas_ready()
listbox = Gtk.ListBox()
listbox.set_selection_mode(Gtk.SelectionMode.NONE)
#Reconstructed First list
counter = 0
for list_element in get_ready[0]:
self.create_med_dialog(list_element[0])
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hbox.pack_start(vbox, True, True, 0)
if list_element[4] in range(10):
minutes = '0' + str(list_element[4])
else:
minutes = list_element[4]
tempo = (str(get_ready[1][counter]) + ":" + str(minutes) + "H")
Pill = Gtk.Label(tempo + "\t" + list_element[0] , xalign=0)
vbox.pack_start(Pill, True, True, 0)
if counter == 0:
button = Gtk.Button(label="Take")
self.demanded_pill = list_element[0]
button.connect("clicked", self.demand_pill)
hbox.pack_start(button, False, True, 0)
listbox.add(row)
self.take_container.pack_start(listbox, False, False, 0)
counter = counter + 1
#The second label is reconstructed
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
info_label = Gtk.Label("Next Pill:", xalign=0)
self.take_container.pack_start(info_label, False, False, 10)
get_next = self.database.get_tomas_next()
listbox = Gtk.ListBox()
listbox.set_selection_mode(Gtk.SelectionMode.NONE)
#The second list is reconstructed
counter = 0
for list_element in get_next[0]:
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hbox.pack_start(vbox, True, True, 0)
if list_element[4] in range(10):
minutes = '0' + str(list_element[4])
else:
minutes = list_element[4]
Pill = Gtk.Label(list_element[0], xalign=0)
vbox.pack_start(Pill, True, True, 0)
label = Gtk.Label(str(get_next[1][counter])
+ ":" + str(minutes) + "H")
hbox.pack_start(label, False, True, 0)
listbox.add(row)
counter = counter + 1
self.take_container.pack_start(listbox, False, False, 0)
self.take_container.set_visible(True)
self.stack.add_named(self.take_container, "Takes")
当我的堆栈刷新时,所有内容都会消失,但我希望他们在销毁后再次创建标签。
答案 0 :(得分:0)
从代码片段看,您似乎没有将创建的小部件添加到任何容器中。除非您在其他地方执行此操作,否则listbox
和self.take_container
已创建,但从未添加到任何容器中。