Deleting parts of a frame using grid_forget Tkinter - python

I have used the following code to delete a section of my frame (wish to delete the number of boxes currently showing - this can vary):
for i in xrange(self.number_boxes):
self.box[i].grid_remove()
self.choice_title.grid_remove()
I however end up with the following:
What am I doing wrong to be stuck with the last part of the main window staying there?!
I have the root window, then a main window, 'win1' in which a frame 'frame_table' holds all the table. The background is set to black.
UPDATE: Corresponds to changing options in OptionMenu:
Rather than having created seperate frames I have just created a set of entry boxes in the current frame 'frame_table'. When a 'list' option is chosen, the user inputs the amount of boxes to be created. With the other option it's always 2 boxes which are created. With the 'fixed' value, all boxes need to be deleted as no additional boxes are required.
Therefore, if one goes from 'list' to 'other option in menu (not fixed)', the boxes from the 'list' option need to be deleted prior to creating the new boxes.

The idiom:
for i in xrange(self.number_boxes):
self.box[i].grid_remove()
self.choice_title.grid_remove()
should rarely be necessary in python. Perhaps you aren't seeing your boxes removed because your self.number_boxes is incorrect (maybe you forgot to update it somewhere). A better way to do it is:
for box in self.boxes:
box.grid_remove()
else:
self.choice_title.grid_remove()
This may (or may not) solve your problem.

Related

In wxpython, how to set position of objects within a wxScrolledWindow

I am writing a kicad plugin, and I need to create a GUI for this plugin. Because kicad uses wxpython, that is what I am using.
I have already figured out that placing my ui items using the layout sizers just isn't gonna give me the control I need to create the window I want. I know I can set the position of elements, and have been using that to create the ui I need.
The problem however, is that my window gets bigger than what would be reasonable (in some situations). Therefore I want to make it scrollable.
I have been playing around with wxformbuilder, and I found the wxScrolledWindow. That got me this far:
This is roughly what I want, except, when you want to place stuff within the scrolledWindow, you have to place one of the "sizers" in it (as far as I can tell at least), in which you place your buttons. The problem with that is, that, to my knowledge, setting the position of buttons in any of the sizers just has no effect at all.
So, my question is: how do I achieve this effect? and, is this even possible?
edit:
As an example of what I am trying to put within the scrolledwindow, this is a rough version of the ui I want to create (and want to be scrollable). (I want to eventually have, probably an icon button above each of the checkbox columns to indicate what they are for).
The final result would need to look something like this (the white squares being small images / buttons, also, in reality being not on the window bar,but in its own not scrolling section):
An example of something I wasn't able to achieve using sizers is, getting those checkboxes so close together, without making them appear off center. Different widgets seem to have different sizes, and checkboxes without border are especially small, so they end up appearing off center, example:
Also, those images above each column of checkboxes, which don't scroll, need to line up with the X coordinates of those scrolling checkboxes, which also seems very non trivial. Though also really hard to get right if I could give everything exact coords, so I might need to give up on that specific idea of making those not scrollable.

How to duplicate a widget in second window

I need to do the following: suppose I have a widget opening on a window (as QWidget). That widget includes some plot. I also have a second window (as QMainWindow) where I do stuff to that plot interactively: move it around and resize it. What I want is to create a third window that displays the exact same thing as the first window (the one with the plot) in real time. How could I go on doing this?
Why do I want this? The first window is going to be hidden and I want the third window so as to inspect that the correct thing is happening on the first one.
Cannot duplicate widgets. The closest thing is to create 2 widgets and in one of them you have to track the changes and apply them to the second (and vice versa). This task is not easy so I would recommend you only track some characteristics.

Tkinter: Is it possible to change the stacking order of placed Frames?

I've been experimenting with Frames placed in the root window. As far as I can see, the stacking order is determined when the frames are created, the
ones created first being below the ones created later. The order of .place
does not seem to have any effect.
Is there some way of changing the stacking order?
You are probably looking for:
widget.lift() # move to the top of the stack
widget.lift(another) # move to just above another widget
widget.lower() # move to the bottom of the stack
widget.lower(another) # move to just below another widget
Explained here. (This is the best documentation I can find. If you read effbot, it reads like lift and lower only apply to windows, but in fact they also work with other widgets.)

wxpython update wx.statictext inside wx.gridsizer

I am using a Flexgridsizer that contains a mix of statictexts and buttons within it. My flexgridsizer contains 1 column of statictext that never changes, 3 columns that update constantly (sometimes a tenth of a second) and the last column has all buttons that remain the same -- I have about 12 rows.
When I push "go" on my code, the three statictext columns update constantly. I do this by self.text1.SetLabel('newtext'). This works great. However, I initially set up the gridsizer so the statictext is centered. Therefore, when i run my code, after updating each cell, i run self.panel.Layout(). This helps get my columns centered again.
The problem with this is that since I do so much updating, it causes my buttons in the last column to look like they are moving left and right (since it appears to be resetting the layout of the buttons). I want the buttons to "stay still". To fix this, I removed the self.panel.Layout() BUT this now makes all my text be right-justified.
Is there any way to apply the Layout() to just specific columns of the gridsizer? I really need to keep the gridsizer if possible. I have also seen the "noautoresize" but one of my columns experiences texts of different lengths at each update.
Any thoughts? Thanks!
Try setting the StaticText size to something specific, like (100, -1). That way it should stay the same unless you happen to apply a string that's greater than the size you set. I'm not sure what happens then, but probably it would get truncated. However, if you're updating it so fast that you can't read it to begin with, I don't think this will be an issue.

Pygtk: CellRenderer using up all vertical space

I made a user interface with a ComboBox. I'm using glade so I'm doing the following at runtime
combo_box.set_model(liststore)
cell = gtk.CellRendererText()
combo_box.pack_start(cell,False)
combo_box.add_attribute(cell,'text',0)
And when I click on the ComboBox the cellrenderer takes up all the vertical space of the screen. However, if I limit the number of items in the liststore, and the cellrenderer does not need a to scroll, the problem disappears.
Here's a picture of the problem:
What is happening?
Thank you for your time.
From what I know this is in GTK+ by design (though I have no references, and could equally be completely wrong). The idea is that when you have a list of items in a ComboBox or Menu, which forces the list off the screen. GTK+ makes a decision to place the first item both at the top of the list, and beneath you mouse cursor.
This means that you have the scrolling effect to reach items at the bottom, which GTK+ indicates by creating scrollable whitespace.
The easiest way around this is to structure the items into submenus, but this again could fall over on a small-sized screen.

Categories