python - How to get background of textview in pygobject “gtk3”? -


i'd current background color of textview change , restore later.

here tried:

context = textview.get_style_context() state = gtk.stateflags.normal color = context.get_background_color(state) 

i tried possible states, none returns correct background color (white in case)

any idea how it?

i'm not sure specific problem without seeing more code, here quick example overrides background , restores on button click:

from gi.repository import gtk, gdk import sys   class mywindow(gtk.applicationwindow):     def __init__(self, app):         gtk.window.__init__(self, title="textview example", application=app)         self.set_default_size(250, 100)         self.set_border_width(10)          self.view = gtk.textview()         self.style_context = self.view.get_style_context()         self.default_bg_color = self.style_context.get_background_color(gtk.stateflags.normal)         self.view.override_background_color(gtk.stateflags.normal,                                             gdk.rgba(0, 0, 0, 1))          self.btn = gtk.button(label="click here")         self.btn.connect("clicked", self.on_btn_clicked)          box = gtk.vbox()         box.pack_start(self.view, true, true, 0)         box.pack_start(self.btn, false, false, 0)         self.add(box)      def on_btn_clicked(self, widget):         current_bg = self.style_context.get_background_color(gtk.stateflags.normal)         if current_bg == self.default_bg_color:             self.view.override_background_color(gtk.stateflags.normal,                                                 gdk.rgba(0, 0, 0, 1))         else:             self.view.override_background_color(gtk.stateflags.normal,                                                  self.default_bg_color)   class myapplication(gtk.application):     def __init__(self):         gtk.application.__init__(self)      def do_activate(self):         win = mywindow(self)         win.show_all()      def do_startup(self):         gtk.application.do_startup(self)  app = myapplication() exit_status = app.run(sys.argv) sys.exit(exit_status) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -