I have a bunch of widgets and right now I am using Hide() and Show() to each widget individually when I flip through different sections/pages of my program.
Because I did this, You can see each widget leaving/showing one by one (which kinda sucks).
Is there anyway to group all these widgets and then be able to Hide() and Show() this group, to avoid this "one by one" habit?
Try using Freeze/Thaw/Layout when you are showing and hiding the widgets. This way they should all appear/disappear at the same time.
Put your group of widgets organized in a sizer in the same parent container (p.e. a panel) and hide the parent. All the widgets disappear with the parent.
Note that sometimes hiding (for example) buttons or checkboxes is not the best solution. Available functionality for the user can be also modulated using widget.Disable()
Related
def change_section_to_main():
SUB_SECTION.destroy()
APP_MAIN_FRAME.pack()
I want to restore the widget "APP_MAIN_FRAME". I thought I could do it with pack() turns out I was wrong. I keep getting this Error >>
_tkinter.TclError: bad window path name ".!frame
You can't "undestroy" a widget. Once it has been destroyed it can no longer be used.
Usually, the solution to this specific problem is to hide the widget rather than destroy it. You can hide it by using one of pack_forget, grid_forget, grid_remove or place_forget depending on exactly what you want to have happen and on which tool (pack, grid, or place) that you used to add it to the window.
If you expect to hide and show a widget often, grid is the best choice since grid_remove will remember how the item was placed. A subsequent call to grid() with no arguments will restore all of the settings. pack and place do not remember the configuration of a widget when it is forgotten.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
I want to add images to wx.Dialog (and then sizer) some like wx.ImageList and display it dynamically.
But I don't want to change already displayed image, I want to add next.
How can I resolve this problem?
I don't think a dialog is a good choice for a growing list of images, but if you have a good argument for that...
Anyway, you should be able to display your images using the wx.StaticBitmap widget. To add another one, use your sizer's Add method, then call the dialog's Layout() method and maybe its Refresh() method. If you plan on displaying many images, then you'll probably want to look at the ScrolledPanel or the ScrolledWindow widgets.
In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say parent_layout.removeItem(child_layout) to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as QLayout doesn't have a hide() method like QWidget does.
The easy solution would be to have an interior widget, not an interior layout. You could assign the layout you desire to the widget, then just remove/hide the widget when you want to do so. A good rule of thumb is if you just want to arrange how widgets appear, then use a layout; if you want to hide/show them as a group, use a widget.
With some help from flupke on #qt, I came up with:
for i in range(0, child_layout.count()):
child_layout.itemAt(i).widget().hide()
parent_layout.removeItem(child_layout)
Which assumes all the child layout's children are widgets. Is there a simpler solution?