在后台删除py.exe

2024-05-12 22:13:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从事tkinter项目。双击python文件时,py.exe文件在后台可见,看起来不太好。那么,有没有办法使py.exe不可见或调整其大小。请帮助我了解您的想法。多谢各位

enter image description here

示例代码:

import tkinter.messagebox
from tkinter import ttk

class Demo1:
    data = []
    def __init__(self, master):
        
        
        self.master = master
        self.label=tkinter.Label(text="Add IP/Hostname")
        self.label.pack()
        self.t=tkinter.Text(self.master,height=20,width=50)
        self.t.pack()
        self.button = tkinter.Button(self.master,height=3,width=10, text="OK"
                                     )
        self.button.pack()

    
def main():
    root = tkinter.Tk()
    app = Demo1(root)
    root.mainloop()


if __name__ == '__main__':
    main()

Tags: 文件textpyimportselfmastermaintkinter
2条回答

这样行吗

import ctypes
ctypes.windll.user64.ShowWindow(ctypes.windll.kernel64.GetConsoleWindow(), 6 )

否则请发布一个示例代码

.py扩展名更改为.pyw。这将抑制控制台窗口

注意:应该将.pyw扩展与pythonw.exe关联起来打开。通常这是由Python安装程序完成的。如果没有,请在第一次单击pythonw.exe文件时选择.pyw。这将形成适当的联系

相关问题 更多 >