我做了一個程序,在一個窗口中顯示了四個終端,但字體太大了。這裏是我的代碼:使用python,GTK + 3,Vte庫。如何更改終端的字體大小?
#!/usr/bin/python shells.py
from gi.repository import Gtk, Vte, Gdk
from gi.repository import GLib
import os
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="shells")
self.resize(1000, 1000)
table = Gtk.Table(2, 2, True)
self.add(table)
palette = [Gdk.color_parse('red')] * 16
terminal1 = Vte.Terminal()
terminal2 = Vte.Terminal()
terminal3 = Vte.Terminal()
terminal4 = Vte.Terminal()
scrolledwindow1 = Gtk.ScrolledWindow()
scrolledwindow1.add(terminal1)
scrolledwindow2 = Gtk.ScrolledWindow()
scrolledwindow2.add(terminal2)
scrolledwindow3 = Gtk.ScrolledWindow()
scrolledwindow3.add(terminal3)
scrolledwindow4 = Gtk.ScrolledWindow()
scrolledwindow4.add(terminal4)
terminal1.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin /sh"],
[], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
terminal2.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
[], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
terminal3.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
[], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
terminal4.fork_command_full(Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"],
[], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None)
terminal1.set_colors(Gdk.color_parse('red'), Gdk.color_parse('black'), palette)
terminal2.set_colors(Gdk.color_parse('green'), Gdk.color_parse('black'), palette)
terminal3.set_colors(Gdk.color_parse('yellow'), Gdk.color_parse('black'), palette)
terminal4.set_colors(Gdk.color_parse('blue'), Gdk.color_parse('black'), palette)
table.attach(scrolledwindow1, 0, 1, 0, 1)
table.attach(scrolledwindow2, 1, 2, 0, 1)
table.attach(scrolledwindow3, 0, 1, 1, 2)
table.attach(scrolledwindow4, 1, 2, 1, 2)
win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
根據文檔Vte set_font我用:
import pango
font = pango.FontDescription()
terminal1.set_font(font)
而且我得到以下錯誤:
AttributeError: type object 'Context' has no attribute '__info__'
的例子是一個堆棧溢出問題: how to enable transparency in vte.Terminal
The n個I使用時,根據本Vte 'decrease-font-size' signal:
terminal1.connect('decrease-font-size', function, data)
def function():
print "press crtl -to decrease font-size"
沒有這一個情況。其餘的也不起作用。 我也注意到,我不能用真正改變一個終端的大小:
terminal1.set_size(30, 29)
似乎改變什麼。
對於這些例子,我僅僅爲了簡單起見而使用了terminal1。 另外一個奇怪的是,當我做「清除」命令,它似乎重新排列自己和字體大小變得更大。 我很抱歉奇怪的英語。這不是我的母語,但我會盡我所能。談到編程時,我只使用python和相關的庫或模塊。我正在使用Linux Debian版本作爲操作系統。
電賀
Sry,但它不起作用。此外,它與他的傢伙的代碼:http://stackoverflow.com/questions/11686510/how-to-enable-transparency-in-vte-terminal而他不需要一個實現信號。也許一切都因爲佈局不好和四個終端同時被打破了? – JonnyPython
再次寫了,工作,完成。謝謝 – JonnyPython