我正在尝试制作一个简单的GUI应用程序,它使用VPython进行可视化。我这样做很成功。但是,当我关闭VPython窗口时,所有其他窗口(我用Tkinter创建的)也会关闭,从而结束整个程序的进程。我已经试过了场景.退出=错误,但id似乎不起作用。在
请有人帮帮我from Tkinter import *
import Tkinter as tk
from visual import *
import serial
root = Tk()
root.wm_title("MultiSense(Desktop Version)")
root.resizable(width=False, height=False)
root.geometry('400x500')
ser = serial.Serial('COM5', 9600)
def dist_window():
windist = tk.Toplevel(root)
windist.wm_title("Distance Sensor")
windist.resizable(width=False, height=False)
windist.geometry('100x150')
def senseDist():
scene.title = "Visualization"
scene.fullscreen = True
scene.visible = False
objDist = cylinder(display=scene, length=20, color=color.green, raduis=1, pos=(-20, 0, 0))
while (1 == 1):
rate(20)
if (ser.inWaiting() > 0):
myData = ser.readline()
distance = float(myData)
objDist.length = distance
btnStart = Button(windist, text="Calculate distance", command=senseDist)
btnStart.pack(side=LEFT, fill=X)
def doNothing():
print 'Nothing'
# ******** Main Window ********** #
menu = Menu(root)
root.config(menu=menu)
fileMenu = Menu(menu)
menu.add_cascade(label="File", menu=fileMenu)
subMenu1 = Menu(fileMenu)
subMenu1.add_command(label="Distance Sensor", command=dist_window)
fileMenu.add_cascade(label='Go to ...', menu=subMenu1, underline=0)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=root.quit)
helpMenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpMenu)
helpMenu.add_command(label="How to use MultiSense", command=doNothing)
helpMenu.add_separator()
helpMenu.add_command(label="About MultiSense", command=doNothing)
root.wm_iconbitmap('windowicon.ico')
root.mainloop()
我对python很陌生。我用Arduino发送串行数据。这个代码真的没有错误。我只想关闭VPython窗口,但它总是关闭整个程序。在