Skip to content
Advertisement

Gtk textview can’t set text [Python]

This is a desktop environment project,I’m try use textview make a terminal,but I got some problem,I can’t use set_buffer() function set text,
My code:

JavaScript

I trying use set_buffer() to set textview’s text(in line 56),but I got an error:

JavaScript

When I change line 56 to
bash1.set_buffer(Gtk.TextBuffer)
later,I still got an error:

JavaScript

How to solve this problem?

Advertisement

Answer

Gtk.TextView.set_buffer() takes a Gtk.TextBuffer as an argument, not a raw string. If you want to change the text inside a Gtk.TextView, you need to do something like this:

JavaScript

Also note that the way you’re implementing this is really inefficient and incorrect. GTK is single-threaded, so the busy loops you’ve now implemented will not only take quite a bit of your CPU, but you’ll also have problems updating GTK like that.

A better way of implementing periodical callbacks is to use GLib.timeout_add_seconds(). This will then also nicely integrate with the main event loop that GTK is already using.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement