我试着把我的python文件转换成exe文件,但exe文件打不开。

问题描述 投票:0回答:1

我写了一个程序,想把它导出为一个.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 但这些也没有用。谁能告诉我发生了什么,如何解决?

python tkinter pyinstaller cx-freeze
1个回答
1
投票

你应该尝试使用 自动Py转Exe我的所有tkinter项目都使用该工具,而且它工作得非常完美。

© www.soinside.com 2019 - 2024. All rights reserved.