Python Programda butona basınca yanıt vermiyor

surafu

Hectopat
Katılım
31 Ağustos 2019
Mesajlar
1.013
Çözümler
4
kodlarımda bir sorun var 1 inci butona basınca program donuyor ve yanıt vermiyor.

import tkinter as tk
import loguru
import pyautogui
import time

def button1_callback():
max_attempts = 99
attempts = 0
tamam_found = False
time.sleep(5)

while attempts < max_attempts and not tamam_found:

pyautogui.click('foto/tikla.png')
time.sleep(15)

try:
location = pyautogui.locateOnScreen('foto/tamam.png')
if location is not None:
left, top, width, height = location
tamam_found = True
pyautogui.click(location)
time.sleep(3)
pyautogui.click(x=1074, y=321)
time.sleep(18)
pyautogui.click(x=1070, y=321)
time.sleep(18)
pyautogui.click(x=1067, y=328)
time.sleep(18)
pyautogui.click(x=975, y=223)
time.sleep(18)
pyautogui.click(x=524, y=358)
time.sleep(18)
pyautogui.click(x=370, y=271)
time.sleep(3)
pyautogui.click(x=461, y=281)
time.sleep(3)
pyautogui.click(x=556, y=284)
time.sleep(3)
pyautogui.click(x=374, y=378)
time.sleep(3)
pyautogui.click(x=465, y=378)
time.sleep(3)
pyautogui.click(x=786, y=533)
time.sleep(3)
pyautogui.click(x=835, y=503)
time.sleep(18)
pyautogui.click(x=299, y=593)
time.sleep(18)
pyautogui.click(x=294, y=578)
time.sleep(18)
pyautogui.click(x=300, y=586)
time.sleep(18)
pyautogui.click(x=709, y=589)
time.sleep(15)

except pyautogui.ImageNotFoundException:
pass

attempts += 1

def button2_callback():
root.quit()

root = tk.Tk()
root.geometry("200x100")

button1 = tk.Button(root, text="Buton 1", command=button1_callback)
button1.pack(pady=10)

button2 = tk.Button(root, text="Buton 2", command=button2_callback)
button2.pack(pady=10)

root.mainloop()
 
Merhaba.
Hatayı bulmak için CMD ile çalıştırın öyle yanıtlayın mesajimi.

Hocam program doğru bir şekilde çalışıyor ancak 1 inci butona bastığım an pencere (yanıt vermiyor) hatası veriyor ve 2 nci buton kullanılamaz oluyor eğer pencereye tıklarsam hata verip program kapanıyor.
 
Hocam program doğru bir şekilde çalışıyor ancak 1 inci butona bastığım an pencere (yanıt vermiyor) hatası veriyor ve 2 nci buton kullanılamaz oluyor eğer pencereye tıklarsam hata verip program kapanıyor.
Selam hata time.sleep komutundan kaynaklı cozumunu bilmiyorum. ama bişeyler denedim işine yarar belki:
Python:
import tkinter as tk
import loguru
import pyautogui
import time
import threading
attempts = 0
max_attempts = 0
def button1_callback():
    print("test")
    max_attempts = 99
    attempts = 0
    tamam_found = False

    time.sleep(5)
    return True
while attempts < max_attempts and not tamam_found:

    pyautogui.click('foto/tikla.png')
    time.sleep(15)

#try:
    #location = pyautogui.locateOnScreen('foto/tamam.png')
    #if location is not None:
        #left, top, width, height = location
        #tamam_found = True
        #pyautogui.click(location)
        #time.sleep(3)
        #pyautogui.click(x=1074, y=321)
        #time.sleep(18)
        #pyautogui.click(x=1070, y=321)
        #time.sleep(18)
        #pyautogui.click(x=1067, y=328)
        #time.sleep(18)
        #pyautogui.click(x=975, y=223)
        #time.sleep(18)
        #pyautogui.click(x=524, y=358)
        #time.sleep(18)
        #pyautogui.click(x=370, y=271)
        #time.sleep(3)
        #pyautogui.click(x=461, y=281)
        #time.sleep(3)
        #pyautogui.click(x=556, y=284)
        #time.sleep(3)
        #pyautogui.click(x=374, y=378)
        #time.sleep(3)
        #pyautogui.click(x=465, y=378)
        #time.sleep(3)
        #pyautogui.click(x=786, y=533)
        #time.sleep(3)
        #pyautogui.click(x=835, y=503)
        #time.sleep(18)
        #pyautogui.click(x=299, y=593)
        #time.sleep(18)
        #pyautogui.click(x=294, y=578)
        #time.sleep(18)
        #pyautogui.click(x=300, y=586)
        #time.sleep(18)
        #pyautogui.click(x=709, y=589)
        #time.sleep(15)

#except pyautogui.ImageNotFoundException:
    #pass

attempts += 1

def button2_callback():
    root.quit()

root = tk.Tk()
root.geometry("400x200")
s = threading.Thread(target=button1_callback) # button1 callbck
button1 = tk.Button(root, text="Buton 1", command=s.start())
button1.pack(pady=10)

button2 = tk.Button(root, text="Buton 2", command=button2_callback)
button2.pack(pady=10)

root.mainloop()
 
Selam hata time. Sleep komutundan kaynaklı cozumunu bilmiyorum. Ama bir şeyler denedim işine yarar belki:
Python:
import tkinter as tk.
import loguru.
import pyautogui.
import time.
import threading.
attempts = 0
max_attempts = 0
def button1_callback():
 print("test")
 max_attempts = 99.
 attempts = 0
 tamam_found = False.

 time.sleep(5)
 return True.
while attempts < max_attempts and not tamam_found:

 pyautogui.click('foto/tikla.png')
 time.sleep(15)

#try:
 #location = pyautogui.locateOnScreen('foto/tamam.png')
 #if location is not None:
 #left, top, width, height = location.
 #tamam_found = True.
 #pyautogui.click(location)
 #time.sleep(3)
 #pyautogui.click(x=1074, y=321)
 #time.sleep(18)
 #pyautogui.click(x=1070, y=321)
 #time.sleep(18)
 #pyautogui.click(x=1067, y=328)
 #time.sleep(18)
 #pyautogui.click(x=975, y=223)
 #time.sleep(18)
 #pyautogui.click(x=524, y=358)
 #time.sleep(18)
 #pyautogui.click(x=370, y=271)
 #time.sleep(3)
 #pyautogui.click(x=461, y=281)
 #time.sleep(3)
 #pyautogui.click(x=556, y=284)
 #time.sleep(3)
 #pyautogui.click(x=374, y=378)
 #time.sleep(3)
 #pyautogui.click(x=465, y=378)
 #time.sleep(3)
 #pyautogui.click(x=786, y=533)
 #time.sleep(3)
 #pyautogui.click(x=835, y=503)
 #time.sleep(18)
 #pyautogui.click(x=299, y=593)
 #time.sleep(18)
 #pyautogui.click(x=294, y=578)
 #time.sleep(18)
 #pyautogui.click(x=300, y=586)
 #time.sleep(18)
 #pyautogui.click(x=709, y=589)
 #time.sleep(15)

#except pyautogui.ImageNotFoundException:
 #pass

attempts += 1

def button2_callback():
 root.quit()

root = tk.Tk()
root.geometry("400x200")
s = threading.Thread(target=button1_callback) # button1 callbck.
button1 = tk.Button(root, text="Buton 1", command=s.start())
button1.pack(pady=10)

button2 = tk.Button(root, text="Buton 2", command=button2_callback)
button2.pack(pady=10)

root.mainloop()

Butonlara ayrı thread uygulayarak sorunu çözdüm hocam. Anladığım kadarıyla buton1 e atanan while döngüsü bitmeden hiçbir işlem yapılamıyordu, bende buton1 in görevlerini arka planda yapmasını sağladım.
 

Geri
Yukarı