我为自己玩的游戏制作了一个农场,并希望与他人分享。是的,我知道可以在终端上运行它以保持打开状态。但是,我试图将其作为exe运行,因此我需要弄清楚如何使其保持打开状态。我试图在python 3.8上添加input(),但是由于某种原因它不起作用。可能是因为我的代码中有一阵True:循环。如果有人能告诉我我的代码如何影响到这个问题,以及双击该文件时我可以做些什么来保持文件打开,那就太好了。 这是我的代码:
import pyautogui
import keyboard
import time
from PIL import Image, ImageGrab
import random
shouldDo = False
keyRelease = True
doingExit = False
currentlyWorking = False
doingQuest = False
desiredColor = (69, 216, 252)
desiredQuestColor = (34, 147, 205)
facebookColor = (48, 68, 163)
currentStage = (1087, 858)
currentScreen = ImageGrab.grab().load()
def updateGame():
currentlyWorking = True
time.sleep(4)
pyautogui.moveTo(960, 827)
time.sleep(1)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(currentStage)
time.sleep(1)
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(957, 1028)
time.sleep(1)
pyautogui.click()
time.sleep(1)
currentlyWorking = False
def updateQuests():
doingQuest = True
pyautogui.moveTo(1167, 87)
time.sleep(.5)
pyautogui.click()
time.sleep(.5)
pyautogui.moveTo(1123, 205)
time.sleep(.5)
pyautogui.click()
time.sleep(.5)
pyautogui.moveTo(1122, 345)
time.sleep(.5)
pyautogui.click()
time.sleep(.5)
pyautogui.moveTo(1114, 485)
time.sleep(.5)
pyautogui.click()
time.sleep(.5)
pyautogui.moveTo(1207, 70)
time.sleep(.5)
pyautogui.click()
doingQuest = False
def exitShare():
doingExit = True
pyautogui.moveTo(1213, 268)
time.sleep(.5)
pyautogui.click()
doingExit = False
while True:
if keyboard.is_pressed('`') and keyRelease:
keyRelease = False
shouldDo = not shouldDo
if not keyboard.is_pressed('`'):
keyRelease = True
if shouldDo:
#Auto Clicker:
#pyautogui.click()
#Summoner's Greed Farm:
currentScreen = ImageGrab.grab().load()
currentColor = currentScreen[660, 7]
questColor = currentScreen[1187, 104]
facebookLogo = currentScreen[921, 459]
#19, 191, 111 is what we WANT to get! -This means we are in a game.
#34, 147, 205 is what we WANT for quests!
#if we get desiredColor, it means our game has ended
if currentColor == desiredColor and not currentlyWorking:
updateGame()
if questColor == desiredQuestColor and not doingQuest and not currentlyWorking:
updateQuests()
if facebookLogo == facebookColor and not doingExit and not currentlyWorking and not doingQuest:
exitShare()
就像我说的那样,在末尾添加输入是行不通的(我也已经在终端中进行了测试,没有错误),所以我正在努力解决这个问题。