Skip to content

windowMethods

Squid Coder edited this page Nov 10, 2024 · 1 revision

windowMethods.py

The windowMethods.py script contains a set of functions for creating and managing GUI elements using Tkinter. It supports window creation, layout configuration, and various widget types such as buttons, labels, side panels, checkboxes, and status bars. It also includes functions for handling dynamic widgets like notebooks and lists, as well as handling icon-based UI elements.

1. Window and Layout Creation

create_window(title, sizeX, sizeY)

Creates and returns the main application window.

  • Arguments:

    • title (str): The title of the window.
    • sizeX (int): Width of the window.
    • sizeY (int): Height of the window.
  • Returns:

    • Tk: The created main window.

create_notebook(parent)

Creates and returns a Notebook widget for adding tabs.

  • Arguments:

    • parent (Widget): The parent widget for the notebook.
  • Returns:

    • Notebook: The created Notebook widget.

create_tab(notebook, title, icon=None)

Creates and adds a tab to the provided notebook widget.

  • Arguments:

    • notebook (Notebook): The notebook widget to add the tab to.
    • title (str): The title of the tab.
    • icon (PhotoImage, optional): Optional icon for the tab.
  • Returns:

    • Frame: The created tab frame.

2. Widget Creation

create_side_panel(parent, side='right', width=250, **kwargs)

Creates and returns a customizable static side panel.

  • Arguments:

    • parent (Widget): The parent widget for the side panel.
    • side (str): Specifies which side to place the panel ('left' or 'right').
    • width (int): Width of the side panel.
    • kwargs: Additional styling options (e.g., background color).
  • Returns:

    • Frame: The created side panel.

create_frame(parent, **kwargs)

Creates and returns a basic Frame widget.

  • Arguments:

    • parent (Widget): The parent widget for the frame.
    • kwargs: Additional styling options.
  • Returns:

    • Frame: The created Frame widget.

create_label_frame(parent, label, **kwargs)

Creates and returns a LabelFrame widget.

  • Arguments:

    • parent (Widget): The parent widget for the label frame.
    • label (str): Label text for the frame.
    • kwargs: Additional styling options.
  • Returns:

    • LabelFrame: The created label frame widget.

create_button(parent, text, icon=None, **kwargs)

Creates and returns a Button widget with an optional icon.

  • Arguments:

    • parent (Widget): The parent widget for the button.
    • text (str): The text to display on the button.
    • icon (PhotoImage, optional): Optional image for the button.
    • kwargs: Additional button options.
  • Returns:

    • Button: The created Button widget.

create_label(parent, text, translate=True, **kwargs)

Creates and returns a Label widget.

  • Arguments:

    • parent (Widget): The parent widget for the label.
    • text (str): The text to display on the label.
    • translate (bool): Whether to translate the text using TransMan (default: True).
    • kwargs: Additional label options.
  • Returns:

    • Label: The created Label widget.

create_checkbox(parent, text, state=None, var=None, cmd=None, **kwargs)

Creates and returns a Checkbutton (checkbox) widget.

  • Arguments:

    • parent (Widget): The parent widget for the checkbox.
    • text (str): The text to display next to the checkbox.
    • state (str, optional): Initial state of the checkbox (default: None).
    • var (tk.Variable, optional): Variable to bind the checkbox state.
    • cmd (function, optional): Command function to call when toggling.
    • kwargs: Additional options for the checkbox.
  • Returns:

    • Checkbutton: The created Checkbutton widget.

create_dropdown(parent, contents, **kwargs)

Creates and returns a dropdown (Combobox) widget.

  • Arguments:

    • parent (Widget): The parent widget for the dropdown.
    • contents (list): List of options for the dropdown.
    • kwargs: Additional dropdown options.
  • Returns:

    • Combobox: The created Combobox widget.

create_listbox(parent, items=None, height=5, withScrollbar=True, **kwargs)

Creates and returns a Listbox widget with dynamic updating functionality.

  • Arguments:

    • parent (Widget): The parent widget for the listbox.
    • items (list, optional): List of initial items for the listbox.
    • height (int): Number of visible rows in the listbox.
    • withScrollbar (bool): Whether to add a vertical scrollbar (default: True).
    • kwargs: Additional listbox options.
  • Returns:

    • Listbox: The created Listbox widget.
    • update_listbox (function): Function to update the listbox items.

addSwitcherButtons(parent, selected_option, label1, label2, icon1=None, icon2=None, bg1='lightblue', bg2='lightgrey', font=('Arial', 12))

Creates two switcher buttons with a pressed-down effect.

  • Arguments:

    • parent (Widget): The parent frame for the buttons.
    • selected_option (tk.StringVar): A variable to store the selected button's label.
    • label1 (str): Label for the first button.
    • label2 (str): Label for the second button.
    • icon1 (PhotoImage, optional): Icon for the first button.
    • icon2 (PhotoImage, optional): Icon for the second button.
    • bg1 (str): Background color for the first button.
    • bg2 (str): Background color for the second button.
    • font (tuple): Font used for the buttons.
  • Returns:

    • Frame: The frame containing the two buttons.

3. Status Bar and Progress Bar

create_status_bar(parent)

Creates and returns a status bar with a status message area and a hideable progress bar.

  • Arguments:

    • parent (Widget): The parent widget for the status bar.
  • Returns:

    • Frame: The created status bar.
    • update_status (function): Function to update the status message.
    • show_progress_bar (function): Function to show the progress bar.
    • hide_progress_bar (function): Function to hide the progress bar.
    • update_progress (function): Function to update the progress bar value.

4. Icon Handling

on_tab_changed(event, notebook, tab_icons)

Updates tab icons when the tab changes.

  • Arguments:
    • event: The event triggered when the tab changes.
    • notebook (Notebook): The notebook widget.
    • tab_icons (list): List of tuples containing unselected and selected icons for each tab.

load_icons(image_path, size=(32, 32), split=False)

Loads and resizes images for use in Tkinter.

  • Arguments:

    • image_path (str): Path to the image file.
    • size (tuple): Desired size of the icon after resizing (default: (32, 32)).
    • split (bool): Whether to split the image for tab icons (default: False).
  • Returns:

    • PhotoImage: Resized image(s) for use in the application.