首页 > 解决方案 > PyGTK ─ 按钮以滚动窗口展开

问题描述

我试图制作一个 raven 应用程序启动器,但由于某种原因,滚动窗口中的按钮扩展了很多,现在我必须水平滚动。我试过 set_size_request,但没有用。我只能让它比现在更大。一个快速的谷歌没有提供任何有用的信息。这是基本结构:

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, GLib

w=Gtk.Window(title="AppLauncher")
itemslist=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

# For getting the Name of application
def showitems():
    listtest=[]
    for root, dirs, files in os.walk("/usr/share/applications/"):
        for file in files:
            if file.endswith(".desktop"):
                for line in reversed(open("/usr/share/applications/"+file).readlines()):
                    if "Name" in line:
                        wordlist=line.split("=")
                        item=Gtk.Button(label=wordlist[-1].replace("\n",""))
                        item.set_size_request(0,0)
                        itemslist.pack_start(item,0,0,0)
                        break
                continue
showitems()

# main window
def body():
    scroll=Gtk.ScrolledWindow()
    itemslist.set_hexpand(False)
    w.add(scroll)
    scroll.add(itemslist)

body()

w.connect("destroy", exit)
w.move(0,0)
w.set_size_request(400, Gdk.Screen.get_default().get_height())
w.set_default_size(400, Gdk.Screen.get_default().get_height())
w.show_all()
Gtk.main()

标签: pythonpygtk

解决方案


推荐阅读