python - 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()
解决方案
推荐阅读
- php - 如何在查询中添加 where between?
- python - 一起训练多个 tensorflow NN
- python - 使用 urlsplit 从 url 中获取域名
- git - 本地 Git 存储库的文件夹名称可以与存储在 Github 上的版本不同吗?
- android - 如何在 BottomSheetDialog 中为不同的状态 STATE_EXPANDED 和 STATE_COLLAPSED 设置视图?
- javascript - Javascript:可以访问返回 json 的 url 但在获取时发生错误
- python - Python闭包是否需要外部范围超出范围(即结束)
- leaflet - 修改传单库中的缩放中心?setZoomAround 有效但不是交互式的
- javascript - 将 laravel 查询与 DataTable 一起使用
- javascript - 来自对话框的 Google Apps 脚本访问值