有没有人使用过tkinter表?
我有将数据添加到新行的问题。我有一个用户输入对象的输入字段。然后在def onButtonSents()
中,我检查这个单词是否包含在objects
数组中,并将此对象输入表命名对象的第一列,在第二列中,我添加对象的正面情绪,依此类推。我想通过单击按钮添加新行并放入一行值的字典的不同列。这就是我现在所拥有的:
file sentiment_analysis.py:
objects [] #an array of objects which user enters into entry field
positiveSentiments = dict() #dictionary with key - object and positive words which correspond to it
negativeSentiments = dict() #dictionary with key - object and negative words which correspond to it
array_cols = ['Object', 'Positive sentiments', 'Negative sentiments']
var = tktable.ArrayVar()
#below is initialization of my tkinter table
import tktable
array_cols = ['Object', 'Positive sentiments', 'Negative sentiments']
var = tktable.ArrayVar()
table = tktable.Table(frame,
rows = 1,
cols = 3,
roworigin=0,
colorigin=0,
variable=var,)
table.pack(side='bottom', fill='both')
var.set(index='0,0', value = 'Object')
table.tag_configure('active', )
var.set(index='0,1', value = 'Positive Sentiments')
var.set(index='0,2', value = 'Negative Sentiments')
#The method which puts data into the rows of table
def onButtonSents():
table.insert_rows(1)
for i in range (1, 5):
index1 = '%i,%i' % (i, 0)
table.activate(index1)
for key in sentiment_analysis.positiveSentiments.keys():
if key == entry.get():
var.set(index='active', value=entry.get())
for i in range (1, 5):
index2 = '%i,%i' % (i, 1)
table.activate(index2)
for key in sentiment_analysis.positiveSentiments.keys():
if key == entry.get():
var.set(index='active', value=sentiment_analysis.positiveSentiments[key])
for i in range (1, 5):
index3 = '%i,%i' % (i, 2)
table.activate(index3)
for key in sentiment_analysis.negativeSentiments.keys():
if key == entry.get():
var.set(index='active', value=sentiment_analysis.negativeSentiments[key])
但表格的单元格未正确填充。第一个对象如果正确填充但是所有对象变得相同,就像我输入'ubs'一样,当我进入第二个'小麦'时,第一个也变成'小麦',他们的情绪也会改变。
不幸的是,我没有在互联网上找到任何关于此问题的建议。我会非常感谢任何建议!