English 中文(简体)
pygtk: cannot set parent on toplevel widget
原标题:
  • 时间:2010-01-05 16:09:38
  •  标签:
  • python
  • pygtk

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?

最佳回答

Do you try this?

gtk.Widget.reparent(new_parent)

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

问题回答

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.

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.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签