Python Forum
[Tkinter] Sections of the code causes the GUI to freeze. What should I do?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Sections of the code causes the GUI to freeze. What should I do?
#1
Question 
Im kind of a beginner to coding. To be fair its my first coding besides college excercises but I've tried to write small program which purpose is to check if user clicked certain button in other application and if so, it would terminate process of that app.

Everything works pretty much as it should but I noticed that program can't get out of one of sections of the code which causes GUI to freeze. What should I do?

from pynput import *
import pyautogui
from tkinter import *
import psutil

window = Tk()
window.geometry("600x300")
window.title("Zamknij Lige-inator")
window.iconbitmap("logo.ico")
window.config(background="#525252")
window.resizable(False, False)



def check_coords(x1, y1, button, pressed):
    if pressed and pyautogui.locateCenterOnScreen("loot_icon.png", confidence = 0.9) != None: 
        x2, y2 = pyautogui.locateCenterOnScreen("loot_icon.png", confidence = 0.9)

        #print("Image at: {}".format((x2, y2)))
        #print("Cursor at: {}".format((x1, y1)))

        if x2-29<=x1 and x2+29>=x1 and y2-41<=y1 and y2+41>=y1:
            #print("Coordinates matched!")
            for proc in psutil.process_iter():
                if proc.name()=="LeagueClient.exe":
                    proc.kill()
            is_paused = True
    elif pressed:
        #print("Image not found!")
        is_paused = True

is_paused = False

def run():
    global is_paused

    if is_paused == False:
        #print("debug")
        with mouse.Listener(on_click = check_coords) as listen:
            listen.join()
    else:
        is_on = False

is_on = False

def switch():
    global is_on

    if is_on == True:
        b1.config(background="#3eca5a", activebackground="#65c979", text="Start")
        is_on = False
    else:
        b1.config(background="#CA3E47", activebackground="#c95b62", text="Stop")
        is_on = True
        is_paused = False
        run()



f1 = Frame(window, width=580, height=260)
f1.grid(row=0, column=0, padx=(10,10), pady=(20,20))
f1.grid_propagate(False)
f1.config(bg="#414141")

l1 = Label(f1,
text="Zamknij Lige-inator",
font = ("Helvetica", 24),
bg="#313131",
fg="white")
l1.grid(row=0, column=0, columnspan=3, 
padx=53, pady=(20,30), ipadx=98, ipady=20, sticky=EW)

b1 = Button(f1,
text="Start",
bg="#3eca5a",
fg="black",
activebackground="#65c979",
command=switch)
b1.grid(row=1, column=0, columnspan=2, 
padx=(53,0), pady=(0,0), ipadx=150, ipady=40)

b2 = Button(f1,
text="Exit",
bg="#313131",
fg="white",
activebackground="#525252",
command=window.quit)
b2.grid(row=1, column=2, 
padx=(0,53), pady=(0,0), ipadx=60, ipady=40)

window.mainloop()
[Image: 8476dac0cc93f.png]
Im not sure if this is allowed but I'll leave one more comment to "bump" the post
Reply


Messages In This Thread
Sections of the code causes the GUI to freeze. What should I do? - by Wilkk - Dec-15-2022, 05:10 PM
RE: Stuck in function - by deanhystad - Dec-27-2022, 10:09 PM
RE: Stuck in function - by Wilkk - Jan-03-2023, 11:36 AM
RE: Stuck in function - by DeaD_EyE - Jan-04-2023, 12:56 PM
RE: Stuck in function - by Wilkk - Jan-07-2023, 08:49 AM
RE: Stuck in function - by Yoriz - Jan-08-2023, 11:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] mpv window freeze before video end rfeyer 7 5,405 Feb-20-2021, 09:34 PM
Last Post: rfeyer
  [Tkinter] tkinter freeze DeanAseraf1 0 2,652 Jul-20-2019, 07:46 AM
Last Post: DeanAseraf1
  Tkinter GUI freeze petterg 4 14,104 Jul-01-2019, 03:54 PM
Last Post: petterg
  [Tkinter] GUI Freeze/tkinter SamGer 2 5,565 Jun-24-2019, 07:25 PM
Last Post: noisefloor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020