Python tksheet,如何更改列名称

2024-06-28 11:22:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个类似的应用程序:https://i.stack.imgur.com/3CzO0.png带有表格,我想用表格中的数字进行计算

有没有办法更改列名称https://i.stack.imgur.com/nfVuf.png 以及如何使用表1和表2中的数字和mace计算,并将结果放入表3

from tkinter import *
import tksheet

root = Tk()
wrapper = Label(root, text='Seria 2')
wrapper.grid()
sheet1 = tksheet.Sheet(root, width=520, height=160, total_columns=4, total_rows=6, show_x_scrollbar=False, show_y_scrollbar=False)
sheet1.grid()
wrapper1 = Label(root, text='Seria 2')
wrapper1.grid()
sheet2 = tksheet.Sheet(root, width=520, height=160, total_columns=4, total_rows=6, show_x_scrollbar=False, show_y_scrollbar=False)
sheet2.grid()
wrapper2 = Label(root, text='Seria 2')
wrapper2.grid()
sheet3 = tksheet.Sheet(root, width=520, height=160, total_columns=4, total_rows=6, show_x_scrollbar=False, show_y_scrollbar=False)
sheet3.grid()
root.mainloop()

Tags: columnstextfalseshowrootwidthlabelgrid
1条回答
网友
1楼 · 发布于 2024-06-28 11:22:51

以下内容适用于您的目的:

sheet1.headers(["Caption colum 1","Caption colum 2","Caption colum 3","Caption colum 4"])
a = sheet1.get_cell_data(2, 1)                # row 2, column 1
b = sheet2.get_cell_data(0, 0)                # row 0, column 0
text = str(int(a) + int(b))                   # convert to int or whatever and back to string
sheet3.set_cell_data(0, 0, text, redraw=True) # row, line, value, refresh

相关问题 更多 >