Skip to content

Bug when using clipboard_function #311

@matheuskknd

Description

@matheuskknd

Hello again, @ragardner. How are you doing?

I've recently noticed a bug when we use clipboard_function (both custom or the default one) if some cell text has the " character on it. Here follows a sample code and steps for reproduction:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import weakref
from tkinter import messagebox, simpledialog
from typing import Any, Callable, Literal, cast

import customtkinter as ctk
import tksheet


class TableFrame(ctk.CTkFrame):

	def __init__(self, master: Any, **kwargs: Any) -> None:
		super().__init__(master, **kwargs)

		# Creating the spreadsheet as an attribute
		self.sheet: tksheet.Sheet = tksheet.Sheet(
			self,
			headers=["A", "B"],
			data=[[1, 'text"'], ['', '3']],
		)
		self.sheet.pack(expand=True, fill="both")
		self.sheet.enable_bindings("all")

		# Creating a highlighted readonly span
		span: tksheet.Span = self.sheet.span(0, 1, 2, 2)
		span.highlight(bg="green", fg="black", redraw=False)
		span.readonly(True)


def main():
	ctk.set_appearance_mode("light")
	ctk.set_default_color_theme("blue")

	root = ctk.CTk()
	root.geometry("800x400")
	root.title("customtkinter + tksheet")

	tabela = TableFrame(root)
	tabela.pack(expand=True, fill="both", padx=10, pady=10)

	root.mainloop()


if __name__ == "__main__":
	main()

Steps to reproduce:

Scenario 1: WORKS 100%

  1. Select cell B1, then press CTRL+C (same using the rc copy feature)
  2. Now paste the text into a notepad (Windows Notepad, for example)
  3. The pasted text will perfectly correspond to the one inside the B1 cell

Scenario 2: FAILS

  1. Select cells B1 to B2, then press CTRL+C (same using the rc copy feature)
  2. Now paste the text into a notepad (Windows Notepad, for example)
  3. The pasted text corresponding to the cell B1 will not represent properly the text actually inside it

Scenario 3: FAILS

  1. Select cells A1 to B1, then press CTRL+C (same using the rc copy feature)
  2. Now paste the text into a notepad (Windows Notepad, for example)
  3. The pasted text corresponding to the cell B1 will not represent properly the text actually inside it

Tested on: Windows 11, Python 3.12.8 and tksheet 7.5.12

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions