Widgets Render
This module provides a simplified way to handle widget layouts (grid, pack, place).
Contains the implementation of the class WidgetsRender
Classes:
|
Perform element creation and rendering in one command. |
- class tkextras.widgets_render.WidgetsRender(render_params: dict | None = None, *args, **options)[source]
Bases:
objectPerform element creation and rendering in one command. Without creating a variable unnecessarily. Combines general parameters for the arrangement of elements and parameters for a specific element.
Methods:
param_prepare([pack_params, func])Combines the packing parameters pack_params of the object with the parameters of the main object of class WidgetsRender.
rgrid(obj[, render_params])Implementation of the tk.Widget.grid() method as a wrapper function
rpack(obj[, render_params])Implementation of the tk.Widget.pack() method as a wrapper function
rplace(obj[, render_params])Implementation of the tk.Widget.place() method as a wrapper function.
- param_prepare(pack_params: dict | None = None, func: str = 'grid') dict[source]
Combines the packing parameters pack_params of the object with the parameters of the main object of class WidgetsRender. Brings it in line with the rendering function.
- Parameters:
pack_params – parameters pack_params of the current object.
func – the rendering function.
- Returns:
combined packing parameters.
- rgrid(obj: Widget, render_params=None)[source]
Implementation of the tk.Widget.grid() method as a wrapper function
- Parameters:
obj – Element to rendering
render_params – Dictionary with element parameters
- Returns:
Rendered element
Treeview DataFrame
This module enhances ttk.Treeview by integrating pandas.DataFrame, allowing dynamic filtering, checkbox handling, and event management.
Contains the implementation of the class TreeviewDataFrame.
Classes:
|
Special tree implementation for working with boolean marks (by default {"check": "✔", "uncheck": " "}). |
- class tkextras.treeview_dataframe.TreeviewDataFrame(parent: Widget | Tk, dataframe: DataFrame = None, render_params: dict = None, *args, **kwargs)[source]
Bases:
WidgetsRender,TreeviewSpecial tree implementation for working with boolean marks (by default {“check”: “✔”, “uncheck”: “ “}). Supports optional Filtering and “mark all” widgets. Simple loading and unloading of a dataframe containing the current state of the tree for further work.
Methods:
make_tree([df])Builds the tree according to the dataframe
column(column[, option])Override column method with DataFrame.
insert(parent, index[, iid])Inserts a new row into the Treeview and synchronizes it with the DataFrame.
set(item[, column, value])Enhanced tt.Treeview set method for synchronization with a DataFrame.
item(item[, option])Override tk.Treeview item method with DataFrame synchronization.
delete(*items[, inplace])Override tk.Treeview delete method with DataFrame synchronization.
flag_inverse(value)Inverts the state of the cell flag
toggle_cell(event)Handles cell clicks to change flags.
rebuild_tree([dataframe])Rebuilds the tree according to the dataframe
filter_by_name([keyword])Filter DataFrame rows based on a keyword and update Treeview.
Filter updated event.
Generation of an all_checked flag updated event
is_all_checked(column)Checking the column status (all cells are marked)
all_checked_update([column])Update the state of all (or one) flags, if column is not 0.
transform_df(load_df, first_column)Moves the specified column to the first position in the DataFrame.
filter_widget(parent)Tree filtering widget by word or part of it "Filter" button Applies a filter "Restore" = clearing the filter value, returning the tree to its original state
checkbox_widget(parent)The widget returns "check all" checkboxes for each column, starting with the second one.
Attributes:
The attribute that automatically creates a copy _svars, so that each object has an isolated copy
- make_tree(df: DataFrame = None)[source]
Builds the tree according to the dataframe
- Parameters:
df – the dataframe for building
- Returns:
None
- property svars
The attribute that automatically creates a copy _svars, so that each object has an isolated copy
- Returns:
dict, isolated svars
- insert(parent: str, index: int | Literal['end'], iid: str | int | None = None, **kw)[source]
Inserts a new row into the Treeview and synchronizes it with the DataFrame.
- Parameters:
parent – Parent node for Treeview (usually “” for root-level items).
index – Position to insert the item.
iid – Unique identifier for the row. If None, Treeview generates one.
kw – Additional arguments for Treeview insert (e.g., values).
- set(item: str | int, column: None = None, value: None = None) dict[str, Any][source]
Enhanced tt.Treeview set method for synchronization with a DataFrame.
- Parameters:
item – The item ID (iid) in the Treeview.
column – The column name to retrieve or update.
value – The value to set; if None, retrieves the current value.
- Returns:
The value as returned by the original Treeview method.
- item(item: str | int, option: Literal['text'] | None = None, **kw) str[source]
Override tk.Treeview item method with DataFrame synchronization.
- Parameters:
item
option
kw
- Returns:
- delete(*items: str | int, inplace=False)[source]
Override tk.Treeview delete method with DataFrame synchronization.
- Parameters:
items
inplace
- Returns:
- flag_inverse(value: str) str[source]
Inverts the state of the cell flag
- Parameters:
value – incoming flag
- Returns:
inverted flag
- toggle_cell(event)[source]
Handles cell clicks to change flags.
- Parameters:
event – click coordinates
- Returns:
None if the click is outside the target area
- rebuild_tree(dataframe: DataFrame = None)[source]
Rebuilds the tree according to the dataframe
- Parameters:
dataframe – dataframe for rebuilding, if empty, self.df is used
- Returns:
None
- filter_by_name(keyword: str = '')[source]
Filter DataFrame rows based on a keyword and update Treeview.
- Parameters:
keyword – filter string
- Returns:
None
- is_all_checked(column: int) bool[source]
Checking the column status (all cells are marked)
- Parameters:
column – column number
- Returns:
column status
- all_checked_update(column: int = 0)[source]
Update the state of all (or one) flags, if column is not 0.
- Parameters:
column – column number
- Returns:
None
- classmethod transform_df(load_df: DataFrame, first_column: str) DataFrame[source]
Moves the specified column to the first position in the DataFrame. Replace boolean-like values in a DataFrame with custom symbols.
- Parameters:
load_df – the dataframe being loaded
first_column – the name of the column that should become the first
- Returns:
transformed data frame prepared for loading