我有一个名为clock.py的Python脚本.

以下是源代码.

# Source: https://www.geeksforgeeks.org/python-create-a-digital-clock-using-tkinter/

# importing whole module
from tkinter import *
from tkinter.ttk import *

# importing strftime function to
# retrieve system's time
from time import strftime

# creating tkinter window
root = Tk()
root.title('Clock')


# This function is used to
# display time on the label

def time():
    string = strftime('%H:%M:%S %p')
    lbl.config(text=string)
    lbl.after(1000, time)


# Styling the label widget so that clock
# will look more attractive
lbl = Label(root, font=('calibri', 40, 'bold'),
            background='purple',
            foreground='white')

# Placing clock at the centre
# of the tkinter window
lbl.pack(anchor='center')
time()

mainloop()

我将此python脚本作为Windows上的快捷方式.当我双击快捷方式图标时,Python tkinter应用程序将启动一个带有图形用户界面的应用程序,但也会启动一个控制台.这个控制台是多余的.

我怎样才能在不启动控制台的情况下启动这个python脚本呢?修改代码还是通过某些Windows设置?

enter image description here

我正在使用Windows 11.

推荐答案

如果您只想要没有控制台shell 窗口的tkinker窗口,请将文件另存为pyw并使用pythonw作为您的链接

pythonw.exe D:\test.pyw

Python相关问答推荐

Polars:使用列值引用when / then表达中的其他列

如何使用Google Gemini API为单个提示生成多个响应?

在内部列表上滚动窗口

在Mac上安装ipython

"使用odbc_connect(raw)连接字符串登录失败;可用于pyodbc"

使用NeuralProphet绘制置信区间时出错

索引到 torch 张量,沿轴具有可变长度索引

如何启动下载并在不击中磁盘的情况下呈现响应?

如何禁用FastAPI应用程序的Swagger UI autodoc中的application/json?

使用Python和文件进行模糊输出

将scipy. sparse矩阵直接保存为常规txt文件

关于两个表达式的区别

如果有2个或3个,则从pandas列中删除空格

无法在Spyder上的Pandas中将本地CSV转换为数据帧

如何在GEKKO中使用复共轭物

如何强制向量中的特定元素在Gekko中处于优化解决方案中

如何在验证文本列表时使正则表达式无序?

如何使用matplotlib查看并列直方图

为什么dict. items()可以快速查找?

Pythonquests.get(Url)返回Colab中的空内容