【发布时间】:2019-01-18 19:18:39
【问题描述】:
当我在本机 python 编辑器中运行基本代码时,画布保持打开状态。
当我使用 Visual Studio 代码(按 F5 运行)执行相同的 Python 代码时,应用程序会运行,但随后会立即关闭并返回到编辑器。
下面是代码示例:
import sys
from tkinter import *
def mHello():
mtext = ment.get()
mlabel2 = Label(mGui, text = mtext).pack()
for i in range(0, 10):
Label(mGui, text = "hello " + str(i+1)).pack()
mGui = Tk()
ment = StringVar()
mGui.geometry('450x450+500+300')
mGui.title("my test thing")
mlabel = Label(mGui, text = "press to okay button to run the code").pack()
mbutton = Button(mGui, text = "ok", command = mHello, fg = "white", bg = "blue").pack()
mEntry = Entry(mGui, textvariable = ment).pack()
请问如何让 VS 代码的行为与本机编辑器相同?
【问题讨论】:
-
可能是你的窗口没有调用mainloop?
标签: python python-3.x tkinter visual-studio-code