python - 如何使用 Tkinter 在树视图表输出中包装行值?
问题描述
没有包装和编辑的树视图输出我需要在树视图小部件中包装一个行值。我在下面添加了一个示例代码,可以重现我的问题。第一列“属性”中的值应包装成多行,而不是在一个句子中获取行值。因此,可读性受到影响。另外,是否可以使这些行可编辑以添加我们自己的文本?第一列(属性)的第二行值要求对其进行编辑。是否可以在树视图中使行可编辑?请注意,目前我将树视图行值作为存储在变量中的列表列表,以便插入到树视图中。但是出于以下代码中的演示目的,这些值是手动给出的。
第 1 列的第一行值需要包装成多行。需要使第 1 列的第二行值可编辑。] 1
from tkinter import *
import tkinter as tk
from tkinter import ttk
root= Tk()
style = ttk.Style()
style.configure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11)) # Modify the font of the body
style.configure("mystyle.Treeview.Heading", font=('Calibri', 13,'bold')) # Modify the font of the headings
style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders
tree = ttk.Treeview(root,style="mystyle.Treeview") # this is the treeview widget to display the dataframe
column_list_account = ["ATTRIBUTE", "VALUE"] # These are the headings
tree['columns'] = column_list_account # We assign the column list to the widgets columns
tree["show"] = "headings" # this hides the default column
for column in column_list_account: # for each column
tree.heading(column, text=column) # let the column heading =column name
tree.column(column, width=100, stretch =YES) # set the column size to 50px
tree.place(relheight=1,
relwidth=1) # set the height and width of the widget to 100% of its container (self.frame1)
treescroll = tk.Scrollbar(root) # create a scrollbar
treescroll.configure(command=tree.yview) # make it vertical
tree.configure(yscrollcommand=treescroll.set) # assign the scrollbar to the Treeview Widget
treescroll.pack(side="right", fill="y") # make the scrollbar fill the yaxis of the Treeview widget
tree.insert("", "end", values=("Observation_Number ():when the system identidies the keyword is Observation_Number, it will convert the current observation number to character and assign to the target variable.", "Normal")) # inserts each list into the treeview
tree.insert("", "end", values =("Edit me", "Is it possible to edit me as well?"))
root.mainloop()
解决方案
推荐阅读
- python - 使用美丽的汤从各种标签中提取标题
- sql - 如何根据列类型修改表格单元格?
- javascript - 为什么我们要完成 observable?
- service - 为什么配置示例服务文件没有@Injectable 装饰器?
- asp.net-web-api - 使用 NSwag 提供多种结果类型
- c++ - 任何运算符、函数调用和构造函数的通用持续时间计
- filter - 使用文本到语音进行搜索仅适用于语音或文本字段
- python - 从 amazon s3 获取音频文件对象
- c# - linux下的topshelf和.net core
- javascript - 无法从 React 更新到 MySQL 数据库