python 3.6, GUI, tkinter, a button to remove the row - python

i am using python 3, GUI, tkinter.
i use grid method (row and column) to create a table containing info, a button is placed in the end of each row. if someone press that button, the whole row will disappear/destroy and next row will replace it, which function should i use to achieve that?

The grid_forget() method will cause the grid geometry manager to stop managing a widget. So if you put your widgets for a row into a frame and grid that, you can grid_forget the frame to have all the widgets in the frame removed from display together. However, you might want to investigate the Ttk treeview which can display tabular information or the tktable package (see this answer).

Related

Python GUI list with progress bar

I'm trying to make a list where a row has some data that can be represented as text, where the row is selectable, and can contain a progressbar. I can't figure out how to implement this with tkinter, I can set up a selectable list with a treeview element, and a progressbar with the progressbar element. But I can't put them together. While I'm using tkinter right now, I'm open to other packages that would support this. Here's the layout I've been working off of http://i.imgur.com/x9cv29j.png

Tkinter bind mouse clicks to frame

I must be missing something obvious, I have two frames in my Tkinter program, each with a bunch of labels in a grid layout. I want to bind the mouseclick to one of them but not the other. I currently use
root.bind("<Button-1>", mouse_function)
but that also triggers if I click in the other frame. I assumed that using
schedule_frame.bind("<Button-1>", mouse_function)
would work but then I get no response anywhere.
The function I am calling is:
def mouse_function(event):
y = event.widget.grid_info()['row']
x = event.widget.grid_info()['column']
widgets[(y, x)].configure(state="active")
shiftSelection(y,x)
When you bind to the root window, that binding applies to all widgets in that root window. That is why it triggered for either frame. This is standard behavior for tkinter.
When you move the binding to the frame, it stopped working because the frame never saw the event. When you click on the label, it is the label that sees the binding, not the frame (unless you click in the space between labels)
There are at least three ways to solve this problem. One is that you can put the binding on the labels rather than the frame. Another is to keep the binding on the root window, but within the function check to see if the widget is a child of that one frame.
A third solution involves changing the bind tags for the labels. For an in depth example see this answer: https://stackoverflow.com/a/32771893/7432

Clear Window in Tkinter

I have a tkinter GUI that, when opened, is an empty widget with a menu bar on top. Clicking on the options on the menu causes for text boxes, more buttons and more menus to appear in the widget. My problem is that everything overlaps.
I need an easy way to delete everything that is currently there, like a "clear window" option.
I've tried packing everything into a frame and then destroying a frame but, for some reason, it's not working.
Any suggestions?
Ideally, I would make something that checks to see if there is anything (button, text box, menu) in a designated space, and it would delete it all before creating the new widget attributes.
The Problem I was having was fixed by creating a new frame within each function and having the code destroy any previously existing frames with Frame.destroy().
My second problem, where widgets within my frame were not, appearing was being caused by how Tkinter frames automatically resize to fit the original widgets. Therefore, when I added widgets to the frame, the frame remained the size of the first widget and didn't show the new buttons. I used frame.pack_propagate(0) to force the frame to remain the specified size.

Scroll a group of widgets in Tkinter

I want to make a whole column of various widgets scrollable in a Tkinter GUI, like so:
Tkinter can only attach scrollbars to certain widgets, of which, frames are not included. Making a scollable column is a common practice in interfaces, and there should be a simple solution, but so far, all I have been able to find is this hacky example of a scrollable frame, using a canvas widget. A similar hacky solution was used in a similar stack overflow question.
Is there a commonly accepted way in Tkinter to make a column, or a group of widgets, that is scrollable?
The solution using the canvas is the commonly accepted way to solve this problem. It's really not all that hacky, and the end result can be indistinguishable from having a native scrolling container widget.
If you're making a single column, another option is to use a text widget, and use the widget's ability to embed other widgets. Insert a widget, then insert a newline, insert another widget, etc. You then get the scrolling ability for free. The only thing you need to worry about is configuring the width of the embedded windows, which isn't too hard to do.

Horizontally oriented listbox using Python and Tkinter

I want to provide a listbox where the user can select (multiple) characters (usually close to 15). Quite often some of these will be sequenced, so a listbox is easier than a validated text entry field.
Since the character combination has a meaning to the user, it is user friendly to orient the listbox horizontally.
Is there an easy way e.g. a theme, setting or subclass of the Tkinter listbox so I do not have to build my own?
No, there is no setting, subclass or theme that will let you do that with a listbox.
What you might want to use instead is a set of check buttons with the indicator turned off so they each appear as a button with a single letter. You can then pack them all horizontally in a frame. With the indicator off, the button will appear sunken when selected, or normal otherwise.

Categories