gtk+ python entry color [closed]

2024/10/16 1:20:15

I'm trying to change the color of an entry gtk3 text. already searched everywhere and can not find a way. I think that is with an entry_buffer but I have no idea how to do it. for gtk2 found easily but my project is all in gtk 3. if anyone can help me I would appreciate.

Answer

So there is this question How to make buttons different colours in Python GTK3 (using gi)? that you might find useful. One of the answers points to an article GTK+ 3 theme: style your applications that explains how you style gtk+ 3 applications in python. It looks like it's exactly what you need. The code below works on Ubuntu 12.04, I could not get it working on Ubuntu 11.04 so I assume you need a relatively recent version of these libraries to do this.

code

from gi.repository import Gtk, Gdkwindow = Gtk.Window()
window.connect("destroy", Gtk.main_quit)
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('style.css')
priority = Gtk.STYLE_PROVIDER_PRIORITY_USER
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, priority)
entry = Gtk.Entry(text='Testing..')
window.add(entry)
window.show_all()
Gtk.main()

style.css

GtkEntry {color: red;background: blue;
}

screenshot

enter image description here

https://en.xdnf.cn/q/117765.html

Related Q&A

converting a text corpus to a text document with vocabulary_id and respective tfidf score

I have a text corpus with say 5 documents, every document is separated with each other by /n. I want to provide an id to every word in the document and calculate its respective tfidf score. for example…

Numpy append array isnt working

Why isnt it appending all the lists? test = {file1:{subfile1:[1,2,3],subfile2:[10,11,12]},file5:{subfile1:[4,678,6]},file2:{subfile1:[4,78,6]},file3:{subfile1:[7,8,9]}} testarray = np.array([50,60,70]…

Select a valid choice ModelChoiceField

Whenever im running form.is_valid() i get the error: Select a valid choice. That choice is not one of the availablechoices.Here is what I do in my view:timeframes = HostTimeFrame.objects.all() if reque…

Let a module file use a global variable?

Forgive me if this is just a super easy solution as I am pretty new to Python. Right now Im trying to make a basic video game, and to save space I decided to make a module for a combat encounter -- so …

Python Subprocess readline hangs() after reading all input

I am trying to readlines from the tcp server that I ran in the same script. I am able to send one command and reads its output but at the end (after reading all outputs) it looks like that program hang…

Python Counting countries in dictionary

Im writing a function that counts the number of times a country appears in a dictionary and returns the country that appeared the most. If more then one country appears the most then it should return a…

How to wait for any socket to have data?

Im implementing a socket-client which opens several sockets at the same time. Any socket may have data at a different time and I want to execute code when any socket has data and is readable.Im not sur…

Retrieving ad URLs

Im looking for a way to retrieve the ad URLs for this website. http://www.quiltingboard.com/resources/What I want to do is probably write a script to continuously refresh the page and grab the ad URLs.…

Extract data (likes) from JSON API using Python

I want to pull the number of likes for my project. Heres my code: import facepy from facepy import GraphAPI from bs4 import BeautifulSoup import json access = CAACEdEose0cBAE3IL99IreDeAfqaVZBOje8ZCqIhf…

No nested nodes. How to get one piece of information and then to get additional info respectively?

For the code below I need to get dates and their times+hrefs+formats+...(not shown) respectively.<div class="showtimes"><h2>The Little Prince</h2><div class="poster&…