在Tkinter中,可以通过以下步骤将包含空格的字符串添加到Treeview列:
import tkinter as tk
from tkinter import ttk
window = tk.Tk()
tree = ttk.Treeview(window)
tree["columns"] = ("column1", "column2")
tree.column("column1", width=100, anchor="w")
tree.column("column2", width=100, anchor="w")
tree.heading("column1", text="Column 1")
tree.heading("column2", text="Column 2")
string_with_space = "Hello World"
tree.insert("", "end", text="Item 1", values=(string_with_space, "Value 2"))
完整的代码示例:
import tkinter as tk
from tkinter import ttk
window = tk.Tk()
tree = ttk.Treeview(window)
tree["columns"] = ("column1", "column2")
tree.column("column1", width=100, anchor="w")
tree.column("column2", width=100, anchor="w")
tree.heading("column1", text="Column 1")
tree.heading("column2", text="Column 2")
string_with_space = "Hello World"
tree.insert("", "end", text="Item 1", values=(string_with_space, "Value 2"))
tree.pack()
window.mainloop()
这样,包含空格的字符串就会被添加到Tkinter Treeview的列中。
领取专属 10元无门槛券
手把手带您无忧上云