为什么创建新选项卡会给我“TypeError: Expected Gtk.Widget, but got GObjectMeta”?

nja*_*lam 5 quickly application-development gtk3 pygi

def on_btn_new_subject_activate(self, widget):
    self.subjects.append_page(Gtk.TextView(), "Testing")
Run Code Online (Sandbox Code Playgroud)

我正在尝试在文本区域上创建一个新选项卡,但是每当事件调用信号时(我单击按钮),就会发生这种情况:

TypeError: Expected Gtk.Widget, but got GObjectMeta
Run Code Online (Sandbox Code Playgroud)

我也尝试过类似“Gtk.GtkTextView()”和“GtkTextView()”的变体但没有成功

我应该使用什么来获取该选项卡中的文本区域?

gau*_*991 1

我认为你必须在使用前初始化 Gtk.TextView()...两天前我也遇到了同样的问题...只需检查以下代码

        self.textview = Gtk.TextView()
        self.textbuffer = self.textview.get_buffer()
        self.textbuffer.set_text("This is some text inside of a Gtk.TextView. "
            + "Select text and click one of the buttons 'bold', 'italic', "
            + "or 'underline' to modify the text accordingly.")
        mywindows.add(self.textview)
Run Code Online (Sandbox Code Playgroud)

请参阅:http ://python-gtk-3-tutorial.readthedocs.org/en/latest/textview.html