【发布时间】:2020-10-14 16:14:15
【问题描述】:
我正在尝试获取网格内的标签值,并且该网格在单击事件后位于按钮内。
这是我的部分代码:
for one_text in text_list:
label_for_button = Gtk.Label(one_text)
label_for_button.set_line_wrap(True)
image_for_button = Gtk.Image.new_from_file("img.png")
grid_in_button = Gtk.Grid()
grid_in_button.add(image_button)
grid_in_button.attach_next_to(label_for_button, image_for_button, Gtk.PositionType.BOTTOM, 1, 2)
grid_in_button.show_all()
button.add(grid_in_button)
button.connect("clicked", self.on_button_clicked)
def on_button_clicked(self, widget):
# here i wanna get the value of the label_for_button
帮助.. 有什么想法吗?谢谢
【问题讨论】:
-
函数的第二个参数包含有关按钮的信息。在函数
on_button_click写print(widget.get_label()),看看是否有效 -
我已经完成了,但它返回“无”。可能是因为它包含按钮、网格和标签在网格内。
-
解决方法是:
widget.get_child().get_child_at(0, 1).get_label()
标签: python python-3.x gtk3