1

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

4

2 回答 2

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, 展开=NO)

在那之后,我尝试的模型都奏效了。

于 2014-11-05T16:52:00.010 回答
1

错误消息准确地告诉您问题所在:

不能在里面使用几何管理器网格。已经有由包管理的奴隶

这意味着您在代码中的某个地方调用.pack(...)了一个作为根窗口子窗口的小部件(“由包管理的从属”),然后您又调用.grid(...)了另一个也是根窗口子窗口的小部件( “不能使用几何管理器网格......”)。

在任何给定的容器窗口(框架、根窗口、顶层)内,所有直接子级只能由网格 OR 包管理,但不能同时由两者管理。

于 2014-11-05T21:30:22.580 回答