python tkinter 显示表格
时间: 2023-07-02 18:12:54
浏览: 163
可以使用tkinter中的Label和Grid进行表格的[显示](https://geek.csdn.net/educolumn/103ca72607c717122e068b9f06a24df6?spm=1055.2569.3001.10083)。首先创建一个tkinter的[窗口](https://geek.csdn.net/educolumn/00d3d1b467be187bf63895f811603770?spm=1055.2569.3001.10083),并设置表格列的数量和名称,然后使用Label和Grid将表格的内容进行填充和[显示](https://geek.csdn.net/educolumn/103ca72607c717122e068b9f06a24df6?spm=1055.2569.3001.10083)。以下是一个简单的例子:
import tkinter as tk
root = tk.Tk()
root.title("Table Example")
# set the columns
columns = ("#", "Name", "Age")
# create the [header](https://geek.csdn.net/educolumn/5aa28203731537fbb8e86c02b176dfd5?spm=1055.2569.3001.10083)
header = [tk.Label(root, text=column) for column in columns]
for i, h in enumerate(header):
h.grid(row=0, column=i)
# create the data rows
data = [
(1, "John", 28),
(2, "Jane", 34),
(3, "Bob", 42),
(4, "[sar](https://geek.csdn.net/educolumn/06b83c763440e3f6811aa5067fdf3b27?spm=1055.2569.3001.10083)ah", 19)
for row, items in enumerate(data):
for column, item in enumerate(items):
label = tk.Label(root, text=item)
label.grid(row=row+1, column=column)
root.mainloop()
```
相关问题
python tkinter 显示xlsx文件
要在Python Tkinter中显示xlsx文件,您可以使用open
python tkinter 导入并显示表格
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)