python1.编程实现:利用tkinker进行GUI编程,图形界面显示以下淡水鱼数据。 已知淡水鱼数据 data = [ ['f1','鲤鱼','杂食性',300], ['f2','草鱼','食草性',240], ['f3','鲫鱼','温水性',500], ['f4','鳙鱼','温水性',400], ['f5','黑鱼','肉食性',480], ](给出两段不同代码)
时间: 2023-07-16 07:14:58 浏览: 77
python 实现GUI(图形用户界面)编程详解
4星 · 用户满意度95%
代码1:
```python
import tkinter as tk
data = [ ['f1','鲤鱼','杂食性',300], ['f2','草鱼','食草性',240], ['f3','鲫鱼','温水性',500], ['f4','鳙鱼','温水性',400], ['f5','黑鱼','肉食性',480], ]
root = tk.Tk()
root.title("淡水鱼数据")
# 创建表格
rows = len(data)
cols = len(data[0])
for i in range(rows):
for j in range(cols):
cell_value = data[i][j]
cell = tk.Label(root, text=cell_value, relief="solid")
cell.grid(row=i, column=j)
root.mainloop()
```
代码2:
```python
import tkinter as tk
data = [ ['f1','鲤鱼','杂食性',300], ['f2','草鱼','食草性',240], ['f3','鲫鱼','温水性',500], ['f4','鳙鱼','温水性',400], ['f5','黑鱼','肉食性',480], ]
root = tk.Tk()
root.title("淡水鱼数据")
# 创建表格标题
tk.Label(root, text="编号", relief="solid").grid(row=0, column=0)
tk.Label(root, text="名称", relief="solid").grid(row=0, column=1)
tk.Label(root, text="饮食习性", relief="solid").grid(row=0, column=2)
tk.Label(root, text="体重(g)", relief="solid").grid(row=0, column=3)
# 创建表格内容
rows = len(data)
for i in range(rows):
tk.Label(root, text=data[i][0]).grid(row=i+1, column=0)
tk.Label(root, text=data[i][1]).grid(row=i+1, column=1)
tk.Label(root, text=data[i][2]).grid(row=i+1, column=2)
tk.Label(root, text=data[i][3]).grid(row=i+1, column=3)
root.mainloop()
```
阅读全文