Untitled

 avatar
unknown
plain_text
4 years ago
1.9 kB
2
Indexable
import time
import pyautogui
import threading
import tkinter as tk
from PIL import Image

fishing = False

def fishingThread():
    global t, f
    fishKey = t.get('1.0', tk.END)[0]

    avg = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    time.sleep(2)
    while(fishing):
        pyautogui.press(fishKey)
        time.sleep(0.5)
        screen: Image.Image = pyautogui.screenshot()
        getCrop = screen.crop((f.winfo_rootx(), f.winfo_rooty(), f.winfo_rootx()+180, f.winfo_rooty()+180))

        r = 0
        for i in range(getCrop.width):
            for j in range(getCrop.height):
                if (getCrop.getpixel((i, j))[0] > 120):
                    r+=1

        if avg.count(0)>=1:
            avg.append(r)
            avg = avg[1::]
            print(avg.count(0))
            continue
        print('%.3f' % (sum(avg) / len(avg)), ': ', r)

        if(r > sum(avg) / len(avg) + 300):
            pyautogui.press('f')
            avg = [0, 0, 0, 0, 0, 0, 0, 0, 0]
            time.sleep(5)
        else:
            avg.append(r)
            avg = avg[1::]
    print("釣魚結束")

def hit_me():
    global bt
    global fishing

    bt.focus_set()
    if (fishing == False):
        fishing = True
        bt.config(text="停止釣魚")
        t = threading.Thread(target=fishingThread)
        t.start()
    else:
        fishing = False
        bt.config(text="開始釣魚")

    return 0

root = tk.Tk()

f = tk.Frame(root,width=180,height=180)
f.place(x=10, y=10)
f["bg"]="green"

t = tk.Text(root)
t.place(x=110, y=220, width=80, height=20)

l = tk.Label(root, text="魚餌按鈕 : ")
l.place(x=10, y=220, width=80, height=20)

bt = tk.Button(root, text="開始釣魚", command=hit_me)
bt.place(x=10, y=250, width=180, height=30)

root.geometry("200x290")
root.resizable(0, 0)
root.wm_attributes("-topmost", True)
root.wm_attributes("-transparentcolor", "green")

root.mainloop()
Editor is loading...