我想创建一个类似Excel样式的表。它应该取决于要显示的数组的大小。 因此,表的列和行都在循环周期内。 在第一行中,我将有一个组合框来选择要筛选的值。 此外,组合框位于不同列编号的循环周期内
创建表时,我无法识别选择了哪个组合框
我该怎么办
例如:
import tkinter
from tkinter import ttk #per button, label etc
from tkinter.ttk import *
import numpy as np #for the matrix tools
def newselection(event, output):
print("Value selected:", event, output)
def ShowTableGui(MatrixToShowIn):
MatrixToShow=np.array(MatrixToShowIn)
RowNumber = MatrixToShow.shape[0]
ArrayCombo=[]
windowx=tkinter.Tk()
windowx.title("Table viewer")
buttonExit = ttk.Button(windowx, text="Close table", command=windowx.destroy)
# buttonExit = ttk.Button(windowx, text="Run Filter", command= lambda: Run_filter(MatrixToShow.shape[1]))
buttonExit.grid(column=0, row=0)
for Col in range (int(MatrixToShow.shape[1])):
ValuesInsert=MatrixToShow[:,Col] # values in column
ValuesInsert=[row[Col]for row in MatrixToShowIn]
ValuesInsert=list(set(ValuesInsert)) # values listed only once
ValuesInsert.sort()
ValuesInsert.insert(0,"*") # add * to filter all
comboExample0 = ttk.Combobox(windowx, state='readonly', values=ValuesInsert)
comboExample0.grid(column=Col+2, row=0)
comboExample0.bind("<<ComboboxSelected>>", lambda event:newselection(comboExample0.get(), "output"))
# comboExample0.bind("<<ComboboxSelected>>", lambda event:newselection(event, "output"))
ArrayCombo.append(comboExample0)
Select=comboExample0.get()
print(Select)
for Row in range (RowNumber):
b = Entry(windowx, text="")
b.grid(row=Row+1, column=Col+2)
b.insert(0,str(MatrixToShow[Row][Col]))
windowx.mainloop()
return()
MatrixToShowIn=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
ShowTableGui(MatrixToShowIn)
由于您的帮助,我终于有时间发布找到的解决方案:
享受罗伯托
相关问题 更多 >
编程相关推荐