簡體   English   中英

我嘗試將我的 python 文件轉換為 exe 文件,但 exe 文件無法打開

[英]I tried converting my python file to exe file, but the exe file won't open

我寫了一個程序,想把它導出到一個 .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 項目,並且效果很好!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM