尝试在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

最佳答案

我注释了第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)

在那之后,我尝试的所有模型都起作用了。

07-27 18:23