我尝试将我的 python 文件转换为 exe 文件,但 exe 文件无法打开



我已经编写了一个程序,希望将其导出到.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,但它们都不起作用。有人能告诉我发生了什么事以及如何解决吗?

您应该尝试使用Auto Py To Exe,我在所有的tkinter项目中都使用了该工具,它运行得很好!

最新更新