有没有人使用过 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”一样,当我输入第二个“小麦”时,第一个对象也变成了“小麦”,他们的情绪也发生了变化。
不幸的是,我在互联网上没有找到任何关于这个问题的建议。我将非常感谢任何建议!