简体   繁体   English

tkinter Canvas window 未从 Powershell 打开

[英]tkinter Canvas window not opening from Powershell

When running on Win10 the following script against the Python 3.8.2 command line, it works just fine, opens a Tk window and displays a triangle:在 Win10 上针对 Python 3.8.2 命令行运行以下脚本时,它工作得很好,打开一个 Tk window 并显示一个三角形:

from tkinter import *
tk = Tk()
canvas = Canvas(tk, width=400, height=400)
canvas.pack()
canvas.create_polygon(10, 10, 10, 60, 50, 35)

However, when running the same script from the PowerShell command line with但是,当从 PowerShell 命令行运行相同的脚本时

& "C:/Program Files (x86)/Python38-32/python.exe" c:/Users/Me/sample.py 

The script terminates without error and without opening the Tk window.该脚本终止时没有错误,也没有打开 Tk window。

How can I get the Tk window to open while calling the Python interpreter from PowerShell command line?如何在从 PowerShell 命令行调用 Python 解释器时打开 Tk window?

I believe the issue is that you forgot to add我相信问题是您忘记添加

tk.mainloop()

at the end of your script which keeps the window running.在保持 window 运行的脚本末尾。

Let me know if adding this fixes your problem.让我知道添加它是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM