【发布时间】:2015-05-27 19:43:58
【问题描述】:
我刚刚更新到 Fedora 22,并使用了 Gnome 3.16。 我正在运行我的一个小应用程序,我收到了弃用警告。 Alignment 对象的 xscale 属性将消失。但是有一个问题,没有它我无法展开按钮的子项。
我创建了这个简单的测试代码:
#!/usr/bin/env python3
import sys
from gi.repository import Gtk
class Application(Gtk.Application):
def __init__(self):
super().__init__()
self.connect('activate', self.on_activate)
self.connect('startup', self.on_startup)
def on_startup(self, app):
self.window = Gtk.ApplicationWindow(application=app)
self.window.set_position(Gtk.WindowPosition.MOUSE)
self.window.set_default_size(600, 200)
button = Gtk.Button(label='test')
image = Gtk.Image.new_from_file('noimage.png')
button.set_always_show_image(True)
button.set_image(image)
# I can't expand without this property bellow
button.get_child().set_property('xscale', 1.0)
self.window.add(button)
def on_activate(self, app):
self.window.show_all()
if __name__ == '__main__':
main_app = Application()
exit_status = main_app.run(sys.argv)
sys.exit(exit_status)
您应该会看到一个小而宽的窗口,里面有一个按钮,覆盖了窗口的所有可用空间。在按钮内,您应该会在左侧看到一个无效的图像图标,在右侧看到一个文本标签。
我使用 xscale 属性将图像与标签分开,这扩大了按钮内 Alignment 对象的大小,并为标签和图像的展开提供了更多空间。我想知道没有它也能达到同样结果的方法。
我使用了 gtk 检查器(在应用程序运行时按 Ctrl+Shift+D)并尝试了该窗口中几乎所有对象中的所有正常和不太正常的属性,但没有成功。我尝试了可靠的搜索引擎,但找不到遇到此类特定问题的人。
【问题讨论】:
标签: python python-3.x gtk gtk3