add to script new ckeckbox button at the rigth of modes switch buttons that called "run offset 1 time" and if enabled it adds info about it state to config_tg-.ini file that script would read at start to adjust state of those button. also next to those new button there shoul be also saveable input field.
import tkinter as tk
from tkinter import font, messagebox
import configparser
import os

class OffsetConfigEditor:
    def __init__(self, master):
        self.master = master
        self.master.title("TG - Offsets and GPU Mode Config Editor")
        
        # Remove maximize button
        self.master.resizable(False, False)  # Disable window resizing
        self.master.attributes("-toolwindow", True)  # This removes the maximize button on Windows
        
        self.bold_font = font.Font(weight="bold")
        
        self.batch_folder = os.path.join("TG", "TGMAIN")
        self.ini_file = os.path.join(self.batch_folder, "config_tg-.ini")
        
        # Ensure batch folder exists
        if not os.path.exists(self.batch_folder):
            messagebox.showerror("Error", f"Batch folder not found: {self.batch_folder}")
            self.master.destroy()
            return
        
        # Read the config file
        self.config = configparser.ConfigParser()
        if not os.path.exists(self.ini_file):
            messagebox.showerror("Error", f"Configuration file not found: {self.ini_file}")
            self.master.destroy()
            return
        
        self.config.read(self.ini_file)
        self.entries = {}

        self.create_offset_fields()

        # Add buttons for mode switching at the bottom, centered
        self.mode_var = tk.StringVar()
        self.check_current_mode()
        
        mode_frame = tk.Frame(self.master)
        mode_frame.grid(row=1000, column=0, columnspan=6, pady=10)
        tk.Radiobutton(mode_frame, text="CUDA mode", variable=self.mode_var, value="CUDA", command=self.switch_mode).pack(side=tk.LEFT, padx=5)
        tk.Radiobutton(mode_frame, text="DirectML mode", variable=self.mode_var, value="DirectML", command=self.switch_mode).pack(side=tk.LEFT, padx=5)

    def create_offset_fields(self):
        """Populate offset fields in a multi-column, multi-row grid layout with aligned entry fields."""
        row = 0
        col = 0
        max_columns = 3

        for section in self.config.sections():
            # Section Label (Bold)
            label = tk.Label(self.master, text=section, font=self.bold_font)
            label.grid(row=row, column=col * 2, columnspan=2, sticky="w", padx=(5, 15))

            offset_x_value = self.config.get(section, 'offset_x', fallback='0')
            offset_y_value = self.config.get(section, 'offset_y', fallback='0')

            # Label and aligned entry for offset_x
            offset_x_label = tk.Label(self.master, text="offset_x:")
            offset_x_label.grid(row=row + 1, column=col * 2, sticky="e", padx=5)
            offset_x_entry = tk.Entry(self.master, width=10)
            offset_x_entry.insert(0, offset_x_value)
            offset_x_entry.bind("<KeyRelease>", lambda e, sec=section, entry=offset_x_entry: self.update_value(sec, 'offset_x', entry.get()))
            offset_x_entry.grid(row=row + 1, column=col * 2 + 1, sticky="w", padx=(0, 10))

            # Label and aligned entry for offset_y
            offset_y_label = tk.Label(self.master, text="offset_y:")
            offset_y_label.grid(row=row + 2, column=col * 2, sticky="e", padx=5)
            offset_y_entry = tk.Entry(self.master, width=10)
            offset_y_entry.insert(0, offset_y_value)
            offset_y_entry.bind("<KeyRelease>", lambda e, sec=section, entry=offset_y_entry: self.update_value(sec, 'offset_y', entry.get()))
            offset_y_entry.grid(row=row + 2, column=col * 2 + 1, sticky="w", padx=(0, 10))

            # Store entries for later access
            self.entries[section] = (label, offset_x_label, offset_x_entry, offset_y_label, offset_y_entry)

            col += 1
            if col >= max_columns:
                col = 0
                row += 3

        # Update last used row for later layout adjustments
        self.last_row = row + 2

    def update_value(self, section, key, value):
        # Set the value with no spaces around `=`
        self.config.set(section, key, value)
        with open(self.ini_file, 'w') as configfile:
            for section in self.config.sections():
                configfile.write(f'[{section}]\n')
                for key, val in self.config.items(section):
                    configfile.write(f'{key}={val}\n')  # No spaces around `=`
                configfile.write('\n')

    def check_current_mode(self):
        tecogan_bat = os.path.join(self.batch_folder, "tecogan.bat")
        tecogan_dml_bat = os.path.join(self.batch_folder, "tecogan_dml.bat")

        if os.path.exists(tecogan_bat) and os.path.exists(tecogan_dml_bat):
            self.mode_var.set("CUDA")
        elif os.path.exists(tecogan_bat) and not os.path.exists(tecogan_dml_bat):
            self.mode_var.set("DirectML")
            self.hide_directml_fields()
        else:
            messagebox.showerror("Error", "Invalid batch file configuration for determining mode.")
            self.master.destroy()

    def switch_mode(self):
        if self.mode_var.get() == "DirectML":
            self.hide_directml_fields()
        else:
            self.show_all_fields()
        tecogan_bat = os.path.join(self.batch_folder, "tecogan.bat")
        tecogan_dml_bat = os.path.join(self.batch_folder, "tecogan_dml.bat")
        tecogan_cuda_bat = os.path.join(self.batch_folder, "tecogan_cuda.bat")

        try:
            if self.mode_var.get() == "DirectML":
                if os.path.exists(tecogan_bat):
                    os.rename(tecogan_bat, tecogan_cuda_bat)
                if os.path.exists(tecogan_dml_bat):
                    os.rename(tecogan_dml_bat, tecogan_bat)

            elif self.mode_var.get() == "CUDA":
                if os.path.exists(tecogan_bat):
                    os.rename(tecogan_bat, tecogan_dml_bat)
                if os.path.exists(tecogan_cuda_bat):
                    os.rename(tecogan_cuda_bat, tecogan_bat)

        except FileNotFoundError as e:
            messagebox.showerror("Error", f"File not found during mode switching: {e}")
        except Exception as e:
            messagebox.showerror("Error", f"Unexpected error during mode switching: {e}")

    def hide_directml_fields(self):
        """Hide fields containing 'BVPP' or 'TG8Xa' in their name and reorganize layout."""
        row = 0
        col = 0
        max_columns = 3

        for section, widgets in self.entries.items():
            label, offset_x_label, offset_x_entry, offset_y_label, offset_y_entry = widgets
            if "BVPP" in section or "TG8Xa" in section:
                label.grid_remove()
                offset_x_label.grid_remove()
                offset_x_entry.grid_remove()
                offset_y_label.grid_remove()
                offset_y_entry.grid_remove()
            else:
                # Re-grid remaining widgets to fill gaps
                label.grid(row=row, column=col * 2, columnspan=2, sticky="w", padx=(5, 15))
                offset_x_label.grid(row=row + 1, column=col * 2, sticky="e", padx=5)
                offset_x_entry.grid(row=row + 1, column=col * 2 + 1, sticky="w", padx=(0, 10))
                offset_y_label.grid(row=row + 2, column=col * 2, sticky="e", padx=5)
                offset_y_entry.grid(row=row + 2, column=col * 2 + 1, sticky="w", padx=(0, 10))

                col += 1
                if col >= max_columns:
                    col = 0
                    row += 3

        # Update last row based on the new layout for buttons
        self.last_row = row + 2

    def show_all_fields(self):
        """Show all fields and reset layout."""
        row = 0
        col = 0
        max_columns = 3

        for widgets in self.entries.values():
            label, offset_x_label, offset_x_entry, offset_y_label, offset_y_entry = widgets
            label.grid(row=row, column=col * 2, columnspan=2, sticky="w", padx=(5, 15))
            offset_x_label.grid(row=row + 1, column=col * 2, sticky="e", padx=5)
            offset_x_entry.grid(row=row + 1, column=col * 2 + 1, sticky="w", padx=(0, 10))
            offset_y_label.grid(row=row + 2, column=col * 2, sticky="e", padx=5)
            offset_y_entry.grid(row=row + 2, column=col * 2 + 1, sticky="w", padx=(0, 10))

            col += 1
            if col >= max_columns:
                col = 0
                row += 3

        # Update last row based on the reset layout for buttons
        self.last_row = row + 2

if __name__ == "__main__":
    root = tk.Tk()
    editor = OffsetConfigEditor(root)
    root.mainloop()