获取笔记本的页数

发布于 2024-08-22 04:43:19 字数 1161 浏览 2 评论 0原文

我有一个笔记本,表单中有一些选项卡,在这个选项卡中,我有用于关闭选项卡的标签按钮。我有这样的代码:

def new_tab(self,label): self.scrolled_window = gtk.ScrolledWindow()

  self.add(self.scrolled_window)
  self.scrolled_window.add_with_viewport(self.editor_access())

  self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

  label = self.create_tab_label(label,self.editor_access)

  self.set_tab_label_packing(self.scrolled_window,False,False,2)
  self.set_tab_label(self.scrolled_window,label)

  self.saving = False
  self.already_save.insert(0,self.get_n_pages() - 1) 

  label.show_all()
  self.show_all()
  return self.editor

def create_tab_label(self, title, tab_child): 框 = gtk.HBox() 标签 = gtk.Label(标题) closebtn = gtk.Button()

  image = gtk.Image()
  image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)

  closebtn.set_image(image)
  closebtn.set_relief(gtk.RELIEF_NONE)

  box.pack_start(label, True, True)
  box.pack_end(closebtn, False, False)

  self.show_all()

  closebtn.connect("clicked",self.close_tab)

  return box 

如何获取用此按钮关闭的选项卡的 page_num ?

谢谢。

I have one notebook with some tabs in my form and in this tabs i have label-button for closing tab. I have code for this:

def new_tab(self,label):
self.scrolled_window = gtk.ScrolledWindow()

  self.add(self.scrolled_window)
  self.scrolled_window.add_with_viewport(self.editor_access())

  self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

  label = self.create_tab_label(label,self.editor_access)

  self.set_tab_label_packing(self.scrolled_window,False,False,2)
  self.set_tab_label(self.scrolled_window,label)

  self.saving = False
  self.already_save.insert(0,self.get_n_pages() - 1) 

  label.show_all()
  self.show_all()
  return self.editor

def create_tab_label(self, title, tab_child):
box = gtk.HBox()
label = gtk.Label(title)
closebtn = gtk.Button()

  image = gtk.Image()
  image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)

  closebtn.set_image(image)
  closebtn.set_relief(gtk.RELIEF_NONE)

  box.pack_start(label, True, True)
  box.pack_end(closebtn, False, False)

  self.show_all()

  closebtn.connect("clicked",self.close_tab)

  return box 

How can i get page_num of tab which I closed with this button?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情旳空白 2024-08-29 04:43:19

如果您的页面小部件永远不会更改,您可以将它们作为用户数据传递给 close_tab 回调:

# In create_tab_label
    closebtn.connect("clicked", self.close_tab, tab_child)

def close_tab(self, button, tab_child):
    # Do something with self.page_num(tab_child)

更新: “page_num 第一个参数必须是 gtk.Widget,而不是 instacemethod “您提到的错误是因为这个:

label = self.create_tab_label(label,self.editor_access)

您似乎正在将一个方法作为 tab_widget 传递。请注意,您之前运行了 editor_access 来创建选项卡子小部件:

self.scrolled_window.add_with_viewport(self.editor_access())

您需要存储此小部件,以便可以将其作为 tab_widget 传递,即:

editor_access = self.editor_access()
self.scrolled_window.add_with_viewport(editor_access)

# ...

label = self.create_tab_label(label, editor_access)

If your page widgets never change, you can just pass them to your close_tab callback as the user data:

# In create_tab_label
    closebtn.connect("clicked", self.close_tab, tab_child)

def close_tab(self, button, tab_child):
    # Do something with self.page_num(tab_child)

Update: The "page_num first argument must be gtk.Widget, not instacemethod" error you mentioned is because of this:

label = self.create_tab_label(label,self.editor_access)

It seems that you are passing a method as tab_widget. Note that you previously you ran editor_access to create the tab child widget:

self.scrolled_window.add_with_viewport(self.editor_access())

You need to store this widget so you can pass it as tab_widget, i.e.:

editor_access = self.editor_access()
self.scrolled_window.add_with_viewport(editor_access)

# ...

label = self.create_tab_label(label, editor_access)
天气好吗我好吗 2024-08-29 04:43:19

# 使用 self.page_num(tab_child) 执行某些操作

但 page_num 第一个参数必须是 gtk.Widget,而不是 instacemethod

# Do something with self.page_num(tab_child)

But page_num first argument must be gtk.Widget, not instacemethod

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文