gtk + python输入颜色 [英] gtk+ python entry color

查看:116
本文介绍了gtk + python输入颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改gtk3条目文本的颜色.已经到处搜索,找不到方法.我认为这是一个entry_buffer,但我不知道该怎么做. gtk2很容易找到,但是我的项目全部在gtk 3中.如果有人可以帮助我,我将不胜感激.

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.

推荐答案

所以有这个问题如何在Python中使按钮使用不同的颜色GTK3(使用gi)?您可能会发现有用.答案之一指向文章 GTK + 3个主题:设置应用程序样式,说明如何在python中设置gtk + 3个应用程序样式.看起来正是您所需要的.下面的代码可在Ubuntu 12.04上运行,我无法在Ubuntu 11.04上运行,因此我认为您需要这些库的最新版本才能做到这一点.

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.

代码

from gi.repository import Gtk, Gdk

window = 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;
}

屏幕截图

这篇关于gtk + python输入颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆