【问题标题】:I tried converting my python file to exe file, but the exe file won't open我尝试将我的 python 文件转换为 exe 文件,但 exe 文件不会打开
【发布时间】:2020-05-10 12:02:53
【问题描述】:

我编写了一个程序,想将其导出为 .exe 文件。我使用了cx-freeze,虽然它通常可以工作,但它并没有与这段代码一起工作。转换后的 .exe 文件打不开。

from ctypes import windll
import tkinter as tk
from tkinter import ttk
from pynput.mouse import Controller
from pynput.mouse import Button, Controller
import time
import webbrowser
from tkinter import messagebox
import keyboard
#from tkinter import *

def start():
    window2.destroy()
    hdc = windll.user32.GetDC(0)
    mouse = Controller()
    webbrowser.open('https://games.htmlgames.com/WhackEmAll/')
    time.sleep(5)
    def wait_until(x, y, operation, colour, wait):
        hdc = windll.user32.GetDC(0)
        if operation == '!':
            while windll.gdi32.GetPixel(hdc, x, y) != colour:
                time.sleep(wait)
        if operation == '=':
            while windll.gdi32.GetPixel(hdc, x, y) == colour:
                time.sleep(wait)

    def click_on(x, y, wait):
        mouse.position = (x, y)
        mouse.click(Button.left, 1)
        time.sleep(wait)

    wait_until(802, 444, '!', 16777215, 1)

    click_on(802, 444, 1)

    click_on(684, 632, 1)

    click_on(847, 539, 0)

    start = time.time()
    end = start + 60


    x_pos = [455, 725, 885, 455, 670, 885, 455, 670, 885,]
    y_pos = [315, 315, 315, 495, 495, 495, 675, 675, 675]
    colour_mole = [15263718, 10277608]

    time.sleep(1)

    window = tk.Tk()
    def exit(event):
        window.destroy()
        stop = 2
    window.bind("<Escape>", exit)
    window.wm_attributes("-topmost", 1)
    window.title("AI")
    label0 = tk.Label(window, text="Welcome to my Whac-A-Mole AI!", font=("Helvetica 10 bold"), fg = "blue")
    label1 = ttk.Label(window, text="Hold ESC for 1 sec to exit the AI", font=("Helvetica 10 bold"))
    label0.grid(row=0, column=0)
    label1.grid(row=1, column=0)


    while time.time() <= end and not keyboard.is_pressed('Esc'):
        window.update_idletasks()
        window.update()
        for x in x_pos:
            for y in y_pos:
                if windll.gdi32.GetPixel(hdc, x, y) in colour_mole:
                    mouse.position = (x, y)
                    mouse.click(Button.left, 1)
    window.destroy()
    window.mainloop()

window2 = tk.Tk()
window2.title("AI")
window2.resizable(0,0)
t2_label0 = tk.Label(window2, text="Welcome to my Whac-A-Mole AI!", font=("Helvetica 10 bold"), fg = "blue")
t2_label1 = ttk.Label(window2, text=" Press Start to begin the AI")
t2_label2 = ttk.Label(window2, text=" You will only be able to stop the program once the game has begun")
t2_label3 = tk.Label(window2, text="WARNING: THIS PROGRAM WILL CONTROL YOUR MOUSE", fg = "red")
t2_label0.grid(row=0, column=0)
t2_button = ttk.Button(window2, text = "Start", command = start)
t2_label3.grid(row = 4, column=0)
t2_button.grid(row = 3, column=0)
t2_label1.grid(row=1, column=0)
t2_label2.grid(row = 2, column=0)
window2.attributes("-topmost", True)


window2.mainloop

我不知道发生了什么。我什至尝试使用exemakerpyinstaller,但这些也不起作用。谁能告诉我发生了什么以及如何解决它?

【问题讨论】:

  • 错误是什么?
  • 虽然会转换,但是exe文件打不开
  • 运行exe时遇到什么错误?

标签: python tkinter pyinstaller cx-freeze


【解决方案1】:

您应该尝试使用Auto Py To Exe,我在我所有的 tkinter 项目中都使用了该工具,并且效果很好!

【讨论】:

  • 这应该是一个评论,在你被允许这样做之前,请坚持发布有助于 OP 的答案
  • @RichBanana,我安装了,但是只有一个html页面
  • @RAW_tech 对,你用html页面做exe
  • @RAW_tech 如果需要,这里有一个关于如何使用 Auto Py To Exe 的教程:Tutorial
猜你喜欢
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 2019-07-13
  • 1970-01-01
  • 2016-11-21
  • 2020-03-26
  • 2018-11-05
  • 2019-12-24
相关资源
最近更新 更多