Python py2exe 窗口显示(tkinter)

编程入门 行业动态 更新时间:2024-10-23 01:32:51
本文介绍了Python py2exe 窗口显示(tkinter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过 py2exe 制作一个 exe.该程序正在使用 Tkinter 显示一个类似弹出窗口的窗口.问题是,当我像这样运行设置时,一切正常:

I'm trying to make an exe by py2exe. The program is showing a popup-like window using Tkinter. The problem is, everything works fine when I run the setup like this:

setup(windows = [{'script': "msg.py"}], zipfile = None)

但是当我尝试制作一个单一文件的 exe 时它失败了:

but it fails when I try to make an one-file exe:

setup(windows = [{'script': "msg.py"}], zipfile = None, options = {'py2exe': {'bundle_files': 1, 'compressed': True}})

实际上最终的 exe 运行没有问题,但它不显示任何窗口.我读过在 Windows 7 上 bundle_files=1 可能有问题,但我也尝试了 bundle_files=2 具有相同的效果.这是我的 msg.py 脚本:

Actually the final exe runs without problems, but it doesn't display any window. I've read there may be problems with bundle_files=1 at Windows 7, but I also tried bundle_files=2 with the same effect. Here is my msg.py script:

from win32gui import FindWindow, SetForegroundWindow from Image import open as iopen from ImageTk import PhotoImage from Tkinter import Tk, Label from threading import Timer from subprocess import Popen import os def Thread(t, fun, arg=None): if arg<>None: x = Timer(t, fun, arg) else: x = Timer(t, fun) x.daemon = True x.start() def NewMessage(): global root if not os.path.exists('dane/MSG'): open('dane/MSG', 'w').write('') root = Tk() img = PhotoImage(iopen("incl/nowa.png")) label = Label(root, image=img) label.image = img label.bind("<Button-1>", Click) label.pack() root.geometry('-0-40') root.wm_attributes("-topmost", 1) root.overrideredirect(1) root.mainloop() def Click(event): global root, exit root.destroy() os.remove('dane/MSG') OpenApp() exit = True def OpenApp(): hwnd = FindWindow(None, 'My program name') if hwnd: SetForegroundWindow(hwnd) else: Popen('app.exe') root, exit = None, False NewMessage()

有什么想法吗?我读过 Tkinter 有一些问题,但有关于编译的问题.我的脚本已编译,并且不会引发任何异常,但不会显示窗口...

Any ideas? I've read there are some problems with Tkinter, but there were about compilation. My script is compiled and it doesn't throw any exceptions, but doesn't show the window...

推荐答案

我最终遇到了同样的问题,我的解决方案包括执行以下操作:

I ended up encountering this same issue, my solution involved doing the following:

添加"dll_excludes": ["tcl85.dll", "tk85.dll"],

在您的 options = {...}

然后手动复制这两个DLL

and then manually copy those two DLLs from

PYTHON_PATH\DLLs\(在我的例子中 C:\Python27\DLLs)

到您的 exe 所在的位置并尝试运行它.

to the location of your exe and try running it.

更多推荐

Python py2exe 窗口显示(tkinter)

本文发布于:2023-07-04 17:21:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   Python   py2exe   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!