How to control GTK inter-line text spacing

The name of the picture


How to control GTK inter-line text spacing



Using GTK (Python), somewhat of a newbie to GTK. I want to display a grid of letters, suitable for e.g. word puzzles, but I can't get the lines to be close enough together. Using Table, with Label objects in each cell. Also tried with TextView in the hope it would give more control than Label, but same result. What's the easiest way to achieve closely-spaced lines? Code sample below.


#!/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()




1 Answer
1



OK, more research has turned up Cairo, which seems to provide the answer. Line drawing and positioning text at arbitrary places are all easily achieved. Sorry to waste your time with dumb noob questions, but I hope this post may be of use to other GTK learners.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP