Python py2exe 窗口显示(tkinter) [英] Python py2exe window showing (tkinter)

查看:63
本文介绍了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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆