输入颜色的python_gtk + python输入颜色

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.

解决方案

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, 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;

}

screenshot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值