pycxsimulator TclError Ubuntu错误
我在Ubuntu 14.04上运行这段小代码
import matplotlib
matplotlib.use('TkAgg')
import pylab as PL
import random as RD
import scipy as SP
RD.seed()
populationSize = 100
noiseLevel = 1
def init():
global time, agents
time = 0
agents = []
for i in xrange(populationSize):
newAgent = [RD.gauss(0, 1), RD.gauss(0, 1)]
agents.append(newAgent)
def draw():
PL.cla()
x = [ag[0] for ag in agents]
y = [ag[1] for ag in agents]
PL.plot(x, y, 'bo')
PL.axis('scaled')
PL.axis([-100, 100, -100, 100])
PL.title('t = ' + str(time))
def step():
global time, agents
time += 1
for ag in agents:
ag[0] += RD.gauss(0, noiseLevel)
ag[1] += RD.gauss(0, noiseLevel)
import pycxsimulator
pycxsimulator.GUI().start(func=[init,draw,step])
但是出现了以下错误信息:
Traceback (most recent call last):
File "/home/joaomeirelles/Documents/USP/TESE/exemplos/pycx-0.31/abm-randomwalk.py", line 49, in <module>
pycxsimulator.GUI().start(func=[init,draw,step])
File "/home/joaomeirelles/Documents/USP/TESE/exemplos/pycx-0.31/pycxsimulator.py", line 48, in __init__
self.initGUI()
File "/home/joaomeirelles/Documents/USP/TESE/exemplos/pycx-0.31/pycxsimulator.py", line 77, in initGUI
self.status.grid(row=1,column=0,padx=2,pady=2,sticky='nswe')
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1985, in grid_configure
+ self._options(cnf, kw))
_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack
[Finished in 0.4s with exit code 1]
有没有人知道这可能是什么问题? 我尝试过使用不同版本的 Tcl/Tk(8.5和8.6),还更新了MGLTools,但都没有解决问题。
谢谢 JM
2 个回答
1
这个错误信息直接告诉你问题出在哪里:
不能在已经有用pack管理的子组件的窗口中使用grid布局管理器
这意味着在你的代码中,有一个地方你对一个属于主窗口的组件使用了.pack(...)
(这就是“用pack管理的子组件”),然后又在另一个同样属于主窗口的组件上使用了.grid(...)
(这就是“不能使用grid布局管理器...”)。
在任何一个容器窗口(比如框架、主窗口或顶层窗口)中,所有直接的子组件只能用grid或者pack来管理,不能同时使用这两种方式。
2
我把第75行的代码注释掉了:#self.notebook.pack(expand=YES, fill=BOTH, padx=5, pady=5 ,side=TOP) 还有第78行的代码:#self.status.pack(side=TOP, fill=X, padx=1, pady=1, expand=NO)
之后,我尝试的所有模型都能正常工作了。