I'm using the HyperTreeList to display a list of items with the name in the first column, and a "Remove" button in the second column. I wrote a function to filter what is displayed in the tree by some text in a TextCtrl. To hide the TreeListItems, I'm doing this:
treelist.HideItem(branch, True)
where treelist is a HyperTreeList and branch is a TreeListItem. The first column hides just fine, but none of the buttons in the second column hide. How do I get all columns in a TreeListItem to hide?
According to the docs, this should work:
treelist.SetColumnShown(column_index, False)
but this will hide that column for everything. If I understand what you're saying, the row you are trying to hide doesn't actually disappear, just the value of the first column. In that case, you might have to refresh the widget with treelist.Update() to get the rest of the row to disappear.
Related
I have searched for answers to this question and always get sent back to printing the selection with print(var.get()).
I don't want to print the selection, but to store it in a variable that I can then use in my code.
For more context, I'm making a simple gui to filter data frames. There are a bunch of dropdown menus from which the user selects specific features. I then want to get all of those features to filter down my data frame to a single entry.
The code snippet below shows what I'm trying, but I don't know how to get the data frame that the function filter_df returns (the data frame df is defined before).
I'd also need to use the value of each previous dropdown menu to remove all the impossible feature values (as in, no entry has both the previous value and the one I select after).
Is any of this possible, or are there elements I'm going to have to find a way around ?
I thank any and all answers in advance, this website is what makes the (or at least my) coding world go round.
app = tk.Tk()
app.geometry('100x200')
detail_app_str = tk.StringVar(app)
detail_app_str.set('Select Scope')
detail_dropedown = tk.OptionMenu(app, detail_app_str, *feature_values)
detail_dropedown.config(width=90, font=('Helvetica', 12))
detail_dropedown.pack(side="top")
def filter_df(*args):
filtered_df = df[(df['A'] == int(detail_app_str.get()))]
return filtered_df
detail_app_str.trace_add("write", filter_df)
I have created a window using tkinter, this window contains a grid of Labels and Entries. In the Entries I have edited some text that I want to save back to the source.
Everything I'm reading so far says that I need to create a separate list and save each entry text variable in the list.
But isn't there a better way to get the values directly from the controls themselves? I know I can loop over mywindow.winfo_children or mywindow.children. So if I can do this, then I should be able to get the text values directly, no?
I just don't know which property to get the value from.
Any ideas out there?
This is the answer.
for child in context.grid_slaves():
if(type(child) is label):
print (child['text'])
if(type(child) is entry):
print(child.get())
I can also find out where I am in the grid like this: child.grid_info() and so I can synch back to the source.
Just to elaborate on the answer.
Loop through the window grid items using the grid_slaves method.
Get the row and column using the widget's grid_info method:
for child in window.grid_slaves():
g_info = child.grid_info()
if type(child) is Button:
row = g_info['row']
col = g_info['column']
text = child['text']
print(row, col, text)
I'm currently developing a cross-platform app (current developing it's under Ubuntu 18.10 and Windows 10) with PyQT 5.13.1 on Python 3.6/3.7. I'm using a QTableWidget that I've initialized in this way:
myTable = QTableWidget()
myTable.setSelectionBehavior(QAbstractItemView.SelectRows)
myTable.setSelectionMode(QAbstractItemView.SingleSelection)
myTable.setAlternatingRowColors(True)
At app's start, my table has two columns but is empty (no rows) and I've a button to add rows one by one. When I do this the first time, the first row is added and it shows with the first cell with a sort of light blue highlight (in both Ubuntu and Windows) and the second cell without it, as in this screenshot:
If I click on any of those cells, the entire row is selected and shows a blue background, accordingly with the setSelectionBehavior initialization. If I CTRL+Click that selected row, it got deselected and goes back with the first cell active/highlighted and the second not. My question is: is there a way to completely remove that highlight (what I'd prefer) or to extend it also to adjacent cell? I've read around that one possible solution wuold be to disable table's focus, but I wish to avoid such a solution.
Thank you all in advance!
The currentIndex exists even when no index is selected, and by default it is highlighted. So to eliminate this behavior you can use a delegate to eliminate that behavior:
class Delegate(QtWidgets.QStyledItemDelegate):
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
option.state &= ~QtWidgets.QStyle.State_HasFocus
delegate = Delegate(myTable)
myTable.setItemDelegate(delegate)
I'm using a ttk treeview like a table full of testdata and I'd like to highlight now the values which are out of range.
Therefore I'd like to color single values (or the background color of this value) in a item and not the whole item (row).
Is this possible?
I've found one example where this problem is solved with a treeview per column, but this is not possible, because I don't want to color the whole column, but just one value...
r
The Treeview widget doesn't allow you to change the color of individual values. You can change the color of an entire row, but not just a single value within a row.
I am new to pyside and have the following situation: I have a model/view in which a column is replaced by push buttons (see related question here). When pressing the button I am able to get the index of this particular button. But how to access e.g. the first element in the same row?
My idea was to create an index pointing to the first element in the row. But how to create a QModelIndex? The documentation does not say to.
Maybe there is another way to 'get/extract' the data from the model in the first column of the row? The second column? The whole row?
I am not sure if the following works:
index2 = index.child(index.row(), 0)
Also, I get the following error (with python3.3):
model.data(index)
TypeError: data() missing 1 required positional argument: 'role'
although the documentation states that role is optional. And what the heck is a role? I want the content of a given data cell.
So how can I achieve my goal?
I found the answer, but mostly by 'guessing'. The pyside documentation is really bad in this aspect...
The solution is:
index2 = index.child(index.row(), 1)
element = model.data(index2, Qt.DisplayRole)
if index is the index the PushButton is located, and you want to get the element of the same row, but the second column.
What index.child() really does: No idea
Why I need a role for model.data: No idea
But it seems to work...