English 中文(简体)
多线环。 Label 无视xalign=0.5
原标题:multiline gtk.Label ignores xalign=0.5

A gtk。 当线-瓦拉布被推翻时,拉贝可能不会被束缚在中心。 例:

import pygtk
pygtk.require( 2.0 )
import gtk

class testwin(gtk.Window):
   def __init__(self):
      gtk.Window.__init__(self)
      width,height = 300,300
      self.set_size_request(width,height)
      self.set_position(gtk.WIN_POS_CENTER)
      self.set_title("test window")

      label = gtk.Label("test text")
      label.set_line_wrap(True)
      label.set_justify(gtk.JUSTIFY_CENTER)
      label.set_alignment(0.5,0.5)
      label.connect("size-allocate",lambda l,s: l.set_size_request(s.width-1, -1))

      self.add(label)
      self.connect("destroy", gtk.main_quit)
      self.show_all()

testwin()
gtk.main()

它想像这一点,这意味着,它把以下几个部分相连接:http://m45.img-up.net/?up=pic122x97.png” rel=“nofollow”http://m45.img-up.net/?up=pic122x97.png。

如果你对第14行(定点_line_wrap)的话,所有东西都是完全罚款的:

请注意,解甲酸 works是罚款的。 因此,这似乎就好像头号论点。 Misc.set_alignment-Function has no effect when line Pack is over.

使用Fedora 16, 64bit, gtk 3.2.4, pygtk 2.24.0, python 2.7.2

问题: 是否打算这样做? 它应如何做,或是否有工作?

问题回答

这确实是一个答案,但它不适于评论。

我会对此进行猜测。 当我把你的代码转换成(PyGObject(PyGTK的继任者)时,它就象你所期望的那样运作。

from gi.repository import Gtk

class testwin(Gtk.Window):
   def __init__(self):
      Gtk.Window.__init__(self)
      width,height = 300,300
      self.set_size_request(width,height)
      self.set_position(Gtk.WindowPosition.CENTER)
      self.set_title("test window")

      label = Gtk.Label("test text")
      label.set_line_wrap(True)
      label.set_justify(Gtk.Justification.CENTER)
      label.set_alignment(0.5,0.5)
      label.connect("size-allocate",lambda l,s: l.set_size_request(s.width-1, -1))

      self.add(label)
      self.connect("destroy", Gtk.main_quit)
      self.show_all()

testwin()
Gtk.main()

当然,如果你 st在PyGTK,而且你可以把他们转往PyGObject右边,那么这一答案就没有解决你的问题。





相关问题
Draw Lines on gtk.TextView

I m trying to show the "selection" of a certain sub-string in a gtk.TextView by drawing a border around the word. The only way to mark text in a TextView that I ve found so far is by placing ...

pygtk: cannot set parent on toplevel widget

I m working on a project that has a glade GUI. I need the main window to have 2 section, divided by a gtk.Hpaned widget (horizontal panes). The left pane would have a tool-bar like layout of buttons,...

pygtk: howto change background of a gtk.TextView widget

I want to make the background of a textview widget black and the foreground white. Been trying the .modify_bg and .modify_fg methods, but none affect the way this thing looks. Can anyone suggest ...

how to properly destroy gtk.Dialog objects/widgets

Noob @ programming with python and pygtk. I m creating an application which includes a couple of dialogs for user interaction. #!usr/bin/env python import gtk info = gtk.MessageDialog(type=gtk....

python GTK container for mjpeg stream

I have an mjpeg stream from a web-cam and would like to display it in an application written in python using pygtk. The stream is a string of bytes from the driver. What widget would be best for ...

Python, thread and gobject

I am writing a program by a framework using pygtk. The main program doing the following things: Create a watchdog thread to monitor some resource Create a client to receive data from socket call ...

热门标签