インポートされた 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))
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()
表示されたウィンドウには、すべてのセルが空のテーブルがあります。
私は Python 2.6、Mac OS 10.6、および Eclipse PyDev を使用していますが、どれも重要ではないと思います。私が重要だと思うのは、理由を特定できないのですが、SourceForge からダウンロードした TkTable モジュールで提供されているサンプル コード ( http://tkinter.unpy.net/wiki/TkTableWrapper ) は、わずかに異なる方法でテーブルを実行します。仕方。それは持っています:
if __name__ == '__main__':
sample_test()
sample_test() に含まれる場所
root = Tk()
と
root.mainloop()
その例の方法が機能するのに、私の方法が機能しないのはなぜですか? あなたが提供できる助けを前もって感謝します。