pygtk:无法在顶级小部件上设置父级

发布于 2024-08-16 20:34:51 字数 296 浏览 10 评论 0原文

我正在开发一个有 Glade GUI 的项目。

我需要主窗口有 2 个部分,由 gtk.Hpaned 小部件(水平窗格)划分。

左窗格将有一个类似工具栏的按钮布局,可能有 3 个或更多。

我需要的是一种创建不同窗口并将它们显示在主窗口的右侧窗格上的方法。这样,当我单击按钮 1 时,子窗口 1 将出现在右侧窗格中。单击按钮2,子窗口2将出现在右侧窗格中。

我不想让窗口左右弹出,而是想将它们重新设置到这个 gtk.Hpaned 的右窗格中。

你如何使用 pygtk 在 python 中做到这一点?

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, maybe 3 or more.

What I need is a way to create different windows and display them on the right pane of the main window. This way, when I click button 1, subwindow1 will appear in the right pane. Click button2, subwindow2 will appear on the right pane.

Instead of having windows pop-up left and right, I want to reparent them to the right pane of this gtk.Hpaned widged.

How do you do this in python with pygtk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-08-23 20:34:51

你试试这个吗?

gtk.Widget.reparent(new_parent)

reparent() 方法将小部件从一个 gtk.Container 移动到另一个。

Do you try this?

gtk.Widget.reparent(new_parent)

The reparent() method moves a widget from one gtk.Container to another.

甚是思念 2024-08-23 20:34:51

您可以在右侧窗格中放置一个笔记本,而不是创建窗口。然后将之前的所有窗口创建为页面。单击该按钮即可在笔记本中显示相应的页面。

Instead of creating windows you could put a notebook in the right pane. Then create all the previous windows as pages. Click on the button can then show the appropriate page in the notebook.

水波映月 2024-08-23 20:34:51

我建议您使用盒子来放置窗格。从一个水平框开始,它基本上将充当您的主窗口:

hboxMain = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=1)

然后是两个用于窗格的垂直框:

vbox0 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)

then add whatever buttons you like to your panes:

btn0 = Gtk.Button()
btn1 = Gtk.Button()
btn2 = Gtk.Button()

vbox0.pack_start(btn0, False, False, 1)
vbox0.pack_start(btn1, False, False, 1)
vbox0.pack_start(btn2, False, False, 1)

(with a VERTICAL Box, pack_start will add the child widget you specify (btnN above) to the top of the box, and continue down as you keep calling pack_start. HORIZONTAL will go left to right.)

Then finally add your vertical boxes to the main horizontal box, and ultimately add the horizontal box to your main window.

hboxMain.pack_start(vbox0, False, False, 1)
hboxMain.pack_start(vbox1, False, False, 1)

win = Gtk.Window(title="Home")
win.add(hboxMain)
win.show_all()

听起来您想将窗口小部件添加到右侧框中。我无法回答这是否可能,因为我认为 Window 更被视为更高级别的容器。我想将一些文本框等打包到右侧框中会更有意义。不知道为什么要添加窗口小部件。来吧,尝试一下。

I would recommend using boxes for your panes. Start with a horizonatal Box that will essentially act as your main window:

hboxMain = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=1)

then two vertical boxes for your panes:

vbox0 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)
vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=1)

then add whatever buttons you like to your panes:

btn0 = Gtk.Button()
btn1 = Gtk.Button()
btn2 = Gtk.Button()

vbox0.pack_start(btn0, False, False, 1)
vbox0.pack_start(btn1, False, False, 1)
vbox0.pack_start(btn2, False, False, 1)

(with a VERTICAL Box, pack_start will add the child widget you specify (btnN above) to the top of the box, and continue down as you keep calling pack_start. HORIZONTAL will go left to right.)

Then finally add your vertical boxes to the main horizontal box, and ultimately add the horizontal box to your main window.

hboxMain.pack_start(vbox0, False, False, 1)
hboxMain.pack_start(vbox1, False, False, 1)

win = Gtk.Window(title="Home")
win.add(hboxMain)
win.show_all()

It sounds like you want to add window widgets to the right-hand box. I can't answer if that is possible as I assume Window is more regarded as a higher level Container. I imagine it would make more sense to pack into the right side box some text boxes, etc. Not sure why you would want to add a Window widget. Go ahead and give it a try.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文