接下來要開始將之前的東西整合起來了,目前期望是做出一個gui畫面,可以指定畫面大小,再來依據畫面去辨識叉叉的位置,最後操作滑鼠或鍵盤去點叉叉,來將廣告關閉
如果要更完整的話可以再加個自動看廣告的功能,不過這邊還是保留給各位來實現了,畢竟這不是主題的重點其實主要還是我懶
先來實作gui吧,先建立main.py的基本架構
from gui import GUI_Handler
from queue import Queue
from threading import Thread
from time import sleep
class Application(Thread):
def __init__(self, q_gui_rsp) -> None:
Thread.__init__(self)
self.q_gui_rsp = q_gui_rsp
def run(self):
while True:
if not self.q_gui_rsp.empty():
msg = self.q_gui_rsp.get(True, 0.5)
self.handle_gui_msg(msg)
sleep(0.1)
def handle_gui_msg(self, msg):
pass
if __name__ == '__main__':
q_gui_rsp = Queue()
app = Application(q_gui_rsp)
app.start()
接下來要生成一個視窗出來,這邊的功能就分到gui.py檔案裡
from tkinter import *
class GUI_Handler():
window = Tk()
window.title("Cross Detect")
window.minsize(width=500, height=500)
window.resizable(width=False, height=False)
def __init__(self, q_gui_rsp):
self.q_gui_rsp = q_gui_rsp
self.item_init()
def get_window(self):
return self.window
然後在主程式執行生成畫面的方法
gui = GUI_Handler(q_gui_rsp)
gui.window.mainloop()
先給它執行看看
生成了一個乾淨的白畫面
再來把一些元件給弄上去
def __init__(self, q_gui_rsp):
self.q_gui_rsp = q_gui_rsp
self.item_init()
def item_init(self):
self.label_range_start = Label(text="range_start:", font=("Arial", 14), padx=5, pady=5)
self.label_range_start.pack()
self.context_range_start = Label(text="", font=("Arial", 14), padx=5, pady=5)
self.context_range_start.pack()
self.label_range_end = Label(text="range_end:", font=("Arial", 14), padx=5, pady=5)
self.label_range_end.pack()
self.context_range_end = Label(text="", font=("Arial", 14), padx=5, pady=5)
self.context_range_end.pack()
self.button_set_range = Button(text="set range", font=("Arial", 14, "bold"), padx=5, pady=5, bg="blue", fg="light green", command=self.set_range)
self.button_set_range.pack()
self.button_cross_detect = Button(text="cross detect", font=("Arial", 14, "bold"), padx=5, pady=5, bg="blue", fg="light green", command=self.cross_detect)
self.button_cross_detect.pack()
再給他運行
明天就開始來做按鈕功能