简体   繁体   English

Python3 Gtk 新标签

[英]Python3 Gtk new tab

I'm just playing with Gtk currently, but was wondering if someone has an example code of a window that has a notebook in it, and with a click of a button or event, it opens a new tab with a Gtk (for example) entry in it and is accessible from further code.我目前只是在玩Gtk ,但想知道是否有人有一个 window 的示例代码,其中有一个笔记本,单击按钮或事件,它会打开一个带有 ZE6094CAAEAA630167CCA0F55BE8Z8 示例的新选项卡进入它,并且可以从进一步的代码中访问。

I can't find any working code like that on the web or on this website.我在 web 或本网站上找不到任何类似的工作代码。

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class MyWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Simple Notebook Example")
        self.set_border_width(3)

        self.box = Gtk.VBox(spacing=6)
        self.add(self.box)
        self._add_tab_button = Gtk.Button(label="Add Tab")
        self._add_tab_button.connect("clicked", self.add_tabs)

        self.box.pack_start(self._add_tab_button, False, False, 5)
        self.counter = 1

        self.notebook = Gtk.Notebook()
        self.box.pack_start(self.notebook, True, True, 5)

        # add two tabs
        self.add_tabs(None)
        self.add_tabs(None)

    def add_tabs(self, button):
        page = Gtk.Box()
        page.set_border_width(10)
        page.add(Gtk.Label(label="Page %s content" % self.counter))
        self.notebook.append_page(
            page, Gtk.Label(label="Page %s" % self.counter))
        page.show_all()
        self.counter += 1

win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM