python - 如何控制 GTK 行间文本间距

标签 python gtk pygtk

使用 GTK (Python),对 GTK 来说有点新手。我想显示字母网格,适合例如字谜,但我无法让线条足够接近。使用表格,每个单元格中带有标签对象。还尝试使用 TextView,希望它能提供比 Label 更多的控制,但结果相同。实现紧密间隔线的最简单方法是什么?下面的代码示例。

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class TableHack(object):

    # Close the window and quit on delete event.
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Table Hack")
        self.window.connect("delete_event", self.delete_event)

        # Create table and fill with text.
        n = 3
        self.table = gtk.Table(n, n, True)
        for row in range(n):
            for col in range(n):
                txt = chr(row * n + col + ord('A'))
                mrkup = "<span size=\"60000\" weight=\"bold\">" + txt + "</span>"
                label = gtk.Label()
                label.set_markup(mrkup)
                self.table.attach(label, col, col+1, row, row+1)
        self.window.add(self.table)

        self.window.show_all()

def main():
    gtk.main()

if __name__ == "__main__":
    tblHack = TableHack()
    main()

最佳答案

好吧,更多的研究出现在开罗,这似乎提供了答案。画线和在任意位置定位文本都可以轻松实现。很抱歉浪费您的时间在愚蠢的菜鸟问题上,但我希望这篇文章对其他 GTK 学习者有用。

关于python - 如何控制 GTK 行间文本间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51488382/

相关文章:

python - Glade/GTK+3/Python 中的 ComboBoxText - 第二次显示时消失

c# - 如何在单声道(GTK)中更改窗口背景颜色?

c - GTK+ 将 gdk_draw_pixbuf 替换为 Cairo

python - gtk 自定义微调按钮

python - 如何从 python 代码滚动 gtk.scrolledwindow 对象

ubuntu - 使用 pyatspi 关闭窗口

python - 在 python 中处理列表

Python - 列表 : How To Remove Empty Attributes From a List of Dictionaries With Nested Properties?

python - 尽管从带包的环境中加载了 jupyter notebook,但在 python 中找不到包

python - 如何创建一个按条件填充创建列表的函数