Python tktable中的单元格为空白,而不是显示内容
导入的TkTable模块中的示例GUI工作正常。但当我尝试在自己的工作中使用TkTable时,表中的每个单元格都是空的。我的测试代码如下Python tktable中的单元格为空白,而不是显示内容,python,tkinter,Python,Tkinter,导入的TkTable模块中的示例GUI工作正常。但当我尝试在自己的工作中使用TkTable时,表中的每个单元格都是空的。我的测试代码如下 from Tkinter import * import TkTable class App: def __init__(self, master): """master is the top level window""" master.geometry(("%dx%d")%(250,60))
from Tkinter import *
import TkTable
class App:
def __init__(self, master):
"""master is the top level window"""
master.geometry(("%dx%d")%(250,60))
master.title("Test")
frame = Frame(master)
frame.pack()
var = TkTable.ArrayVar(frame)
for y in range(6):
for x in range(6):
index = "%i,%i" % (y, x)
var[index] = index
label = Label(frame, text="test2")
label.pack(side = 'top', fill = 'x')
quit = Button(frame, text="QUIT", command=root.destroy)
quit.pack(side = 'bottom', fill = 'x')
test = TkTable.Table(frame,
rows=6,
cols=6,
state='disabled',
width=6,
height=6,
titlerows=1,
titlecols=0,
roworigin=0,
colorigin=0,
selectmode='browse',
selecttype='row',
rowstretch='unset',
colstretch='last',
flashmode='on',
variable=var,
usecommand=0)
test.pack(expand=1, fill='both')
test.tag_configure('sel', background = 'yellow')
test.tag_configure('active', background = 'blue')
test.tag_configure('title', anchor='w', bg='red', relief='sunken')
root = Tk()
app = App(root)
root.mainloop()
显示的窗口有一个包含所有空单元格的表格
我正在使用Python2.6、MacOS10.6和EclipsePydev,尽管我认为这些都无关紧要。我认为重要的是,我从SourceForge下载的TkTable模块中提供的示例代码()以稍微不同的方式运行该表,但我无法指出原因。它有:
if __name__ == '__main__':
sample_test()
其中示例_test()包含
root = Tk()
及
为什么那个示例方法有效,而我的方法无效?提前感谢您提供的任何帮助。您可能需要阅读有关局部变量与全局变量与实例变量
将所有出现的
var
替换为self.var
您可能需要阅读局部变量与全局变量与实例变量的对比
将所有出现的var
替换为self.var
更改脚本:
for y in range(6):
for x in range(6):
index = "%i,%i" % (y, x)
var[index] = index
致:
更改脚本:
for y in range(6):
for x in range(6):
index = "%i,%i" % (y, x)
var[index] = index
致:
请不要只写代码,还要写一个简短的描述为什么。请不要只写代码,还要写一个简短的描述为什么。
for y in range(6):
for x in range(6):
index = "%i,%i" % (y, x)
var.set(index,index)