An issue with the tag add command of the ttk.Treeview widget - cant handle white space

2024/11/18 4:35:30

I have noticed an issue with using the tag add command of a ttk.Treeview widget when activated with the tk.call() method. That is, it can't handle white space in the value of the str() elements of its items argument.

See this answer on how I had implemented the tag add command. Now if /home/user/Desktop/Secret Source is passed in to items, the returned error msg is:

self.tk.call(self.tree._w, 'tag', 'add', tag, items)
_tkinter.TclError: Item /home/user/Desktop/Secret not found

The text Source with one white space is missing from Secret Source. How do I overcome this error?

Answer

The treeview tag add command requires items to be a list, but you're passing a string. When tcl is given a string when it expects a list, the string will be split on whitespace to create a list. That is why it thinks the characters before the space is the whole item id.

https://en.xdnf.cn/q/120113.html

Related Q&A

How to show the ten most overdue numbers in a list

I have asked a question before about this bit of code and it was answered adequately, but I have an additional question about showing the ten most overdue numbers. (This program was a part of an in-cla…

Connect a Flask webservice from a device which is not on the same network

I am not an expert in web programming and know very little about it. I am trying to run a webservice on an EC2 instance (Windows Server 2012R2) and the webservice is written in Python using Flask packa…

why int object is not iterable while str is into python [duplicate]

This question already has answers here:Why is int" not iterable in Python, but str are?(4 answers)Closed 2 years ago.As i know we can not iterate int value while we can iterate strings in python.…

an irregular anomaly in python tuple

i create two identical tuples and use is operator on them the answer that should come is false but when i use it in vscode/atom/notepadd++ it comes true but when i use the same code in pthon run throug…

AttributeError: type object Employee has no attribute Worker

Taking a class on Python coding and trying to use inheritance to code an answer to this problem: Write an Employee class that keeps data attributes for the following piece of information: Employee name…

How to add tag for numbers which in brackets using python regex?

The default strings is:strings123[abc123def456]strings456Add tag for number:strings[abc<span>123</span>def<span>456</span>]strings

How to write program run matrix as below in python?

Thanks for everyones reply. I will explain here. Suppose there is a given matrixx y B = [5,-4,5,-6] [[0,0,0,0], [[0,1,0,1],[0,0,0,0], [0,0,0,0],[0,0,0,0],…

Scraping Dynamic Information

I recently started with coding, I use Python and Pycharm. I Installed and imported the needed "Add-ons" like Selenium. For my first project I tried to get the "address" information …

Combining three RGB images into a single RGB image

I have three RGB images, but each one has only 1 non-zero channel (ie. one has a red channel with 0s in the blue and green channels) and I want to combine them into a single RGB image with the correct …

Parse XML to Table in Python

Im trying to parse XML to table-like structure in Python. Imagine XML like this:<?xml version="1.0" encoding="UTF-8"?> <base><element1>element 1</element1>…