【发布时间】: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
我不知道发生了什么。我什至尝试使用exemaker 和pyinstaller,但这些也不起作用。谁能告诉我发生了什么以及如何解决它?
【问题讨论】:
-
错误是什么?
-
虽然会转换,但是exe文件打不开
-
运行exe时遇到什么错误?
标签: python tkinter pyinstaller cx-freeze