pycxsimulator TclError Ubuntu

时间:2014-07-03 17:11:26

标签: python python-2.7 tkinter tk pycxsimulator

尝试在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 个答案:

答案 0 :(得分: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)

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

答案 1 :(得分:1)

错误消息正好告诉您问题所在:

  

无法使用几何管理器网格。已经有奴隶了   由pack管理

这意味着您的代码中的某个位置在根窗口的子窗口小部件上调用.pack(...)(“由pack管理的从属”),稍后您将调用.grid(...)另一个窗口小部件也是根窗口的子窗口(“不能使用几何管理器网格...”)。

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