2013-08-26 62 views
0

我在实现一些GUI到我的simpy模拟中遇到问题。问题在于如何将GUI(最好是在Tkinter中)添加到简单的项目中。赖特现在甚至有创建一个窗口的问题。我认为这是因为当模拟停止运行时,我不能理解Tkinter代码..我知道这是一个非常普遍的问题,但我不知道如何开始。我想要用Tkinter做的是为我的模拟绘制一个拓扑结构,也许能够改变一些参数,并从GUI中运行它。在tkinter中添加GUI到simpy模拟

我已经添加了一部分,当模拟开始时,对象被创建,整个事情超过十倍大,所以我不知道我是否应该在这里添加它。

initialize() 

network=Network() 


#creating nodes 

node=Node(name='node', function='user', interfaceNum=2, possition=[160,990], homeAddress='0000000000000000020000fffe111111') 
node.engine.stateTable={'wifiassocresp':'self.changeIp(interface, self.HO)','dissconnect':'node.engine.dissconnect(self.interruptCause, self.interruptCause.passSender)','RngRsp':'self.sendBU()', 'MIPv6BindingAck_LCoA':'self.sendBU(RCoA=True)', 'MihN2nHoCandidateQueryRsp':'self.makeHandover()'} 
activate(node, node.start()) 

ap0=Node(name='ap0', function='ap', interfaceNum=2,possition=[200,1000]) 
ap0.engine.stateTable={'dissconnect':'self.dissconnect(self.interruptCause, self.interruptCause.passSender)'} 
activate(ap0, ap0.start()) 

..... there is more nodes, but i cut it becouse I thinks that this is not important 


activate(ha, ha.start()) 

ha.engine.HAadresses={'node':{ 
    'interfaceAddress':[node.interfaceList[0], node.interfaceList[0].address], 
    'homeAddress':[node.homeAddress],}} 


simulation=Tasks() 


network.drawTopology(nodes=[node, ap1,ap2, map1, ap0, internet, ha]) 


allNodes=[node, internet, ap1, ap2, map1, ap0, ha] 
node.apList=[ap0,ap1,ap2] 

ap1.engine.createRouting([node, internet, map1, ap0, ap2, ha]) 
ap2.engine.createRouting([node, internet, map1, ap0, ap1, ha]) 
map1.engine.createRouting([node, ap1, internet, ap0,ap2, ha]) 
ap0.engine.createRouting([node, ap1, ap2, map1, internet, ha]) 
internet.engine.createRouting([node, ap1, map1, ap0,ap2, ha]) 


#here starts the simulation 
activate(simulation, simulation.run(1)) 

simulate(until=100000.0) 

这里是代码亩GUI

from Tkinter import * 
from betaruch import * 

class MainWindow: 
    def __init__(self, master): 
     ramka=Frame(master) 
     ramka.pack() 

     self.przycisk=Button(ramka, text="Wyjscie", fg="red", command=ramka.quit) 
     self.przycisk.pack(side=LEFT) 

     self.witam=Button(ramka, text="Uruchom", command=self.uruchomSymulacje) 
     self.witam.pack(side=LEFT)   

    def uruchomSymulacje(self): 
     pass 

root=Tk() 

onko=MainWindow(root) 


root.mainloop() 

而且它不suppoused做任何事情,但它甚至desn't显示出来。

好吧,也许这会有所帮助。我注意到当我导入Tkinter和matplotlib时会出现问题。所以也许matplotlib也使用tkinter?

+0

托比你好,请考虑将您实际的代码和你的问题的具体描述(异常消息,截图等)。此信息可能有助于解决此问题。 –

+0

我没有任何错误,问题在于该窗口没有出现。 – tobi

回答

1

看起来您正在执行与您的Tkinter代码相同的线程中的betaruch模块的代码,所以这就是您的GUI无响应的原因。为了解决这个问题,你可以在一个新的线程与threading模块执行仿真:

import threading 
from Tkinter import * 
from betaruch import * 

class MainWindow: 
    # ...  

    def uruchomSymulacje(self): 
     thread = threading.Thread(target=a_betaruch_function) # just a reference, without parentheses 
     thread.start() 
+0

谢谢,但我决定通过简单地将我的模拟器分成两个独立的程序来解决它:一个用于模拟,一个用于制作图表,绘图等。但我仍然有同样的问题,但我也注意到了一些问题: import matplotlib.pyplot as plt from Tkinter import *当我删除导入matplotlib窗口时出现,但是用它它们不是 – tobi

+0

确定这是werid,但它似乎是Wing IDE的问题。如果它在标准的Python IDE中运行,那么它们就是相同的代码。有没有人有导入Tkinter的问题? – tobi