Python Forum
maximum recursion depth exceeded
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
maximum recursion depth exceeded
#1
whenever i hit the exit button it gives me this error

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\saba_\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit
exit()
File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit
exit()
File "C:\Users\saba_\Desktop\python\clickerHero.py", line 39, in exit
exit()
[Previous line repeated 985 more times]
RecursionError: maximum recursion depth exceeded

code below

import tkinter as tk
import time
from pynput.mouse import Button, Controller

#creates the window
root = tk.Tk()
root.geometry("600x400")
root.title("attempt1")



#global var

mouse = Controller()
startClickingVar = 0



#def
def startClick():
if startClickingVar == 0:
startClickingVar = 1
while startClickingVar == 1:
time.sleep(1)
mouse.click(Button.left, 1)
time.sleep(1)
else:
pass

def stopClick():
if startClickingVar == 1:
startClickingVar = 0
else:
pass

def exit():
exit()

#


#lables
welcomingLable = tk.Label(root, text="Hi, Welocme to Hero Clicker AutoClicker", font=("arial", 20, "bold"), fg = "blue")
welcomingLable.pack(side=tk.TOP)

#buttons
start = tk.Button(root, text="start", width=25, bg="lightgreen", command=startClick)
start.place(x=50, y=140)

stop = tk.Button(root,text="stop", width = 25, bg="red", command=stopClick)
stop.place(x=350, y=140)

exitButton = tk.Button(root, text="Exit", width = 25, bg="red", command=exit)
exitButton.place(x=200, y=180)


#enterys
numberOfClicks = 1
enterCardInfo = tk.Entry(root, textvariable= numberOfClicks, width=50, bg="orange",)
enterCardInfo.place(x=150, y=100)


# has to stay below so everthing runs within
root.mainloop()
Reply
#2
You have this error because the exit() function calls itself recursively. Replace it with
def exit():
    root.destroy()
Reply
#3
I changed it and it works, Thank you. but now i'm having the problem of when i hit star the loop starts running and i cant shut it down because the exit button doesn't respond. how can i multi thread a button ?
Reply
#4
A good principle is to avoid time.sleep() with GUIs because it freezes the GUI. You can use tkinter's after() method. Something like
startClickingVar = False

def click_forever():
    if startClickingVar:
        mouse.click(Button.left, 1)
        root.after(1000, click_forever)

def startClick():
    global startClickingVar
    if not startClickingVar:
        startClickingVar = True
        click_forever()

def stopClick():
    global startClickingVar
    startClickingVar = False
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyinstaller Maximum recursion bug scales11 8 11,061 Nov-10-2023, 10:26 PM
Last Post: SuzanneKH09
  Max recursion depth.... Error MeloB 2 1,903 Feb-16-2022, 05:21 PM
Last Post: MeloB
  Time Limit Exceeded error loves 5 3,158 Dec-03-2020, 07:15 AM
Last Post: Sofia_Grace
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,770 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Requesting help with my implementation of depth-first search tigerfuchs 6 2,588 Sep-26-2019, 05:47 AM
Last Post: perfringo
  RecursionError: maximum recursion depth exceeded in comparison ? leoahum 11 13,081 Mar-18-2019, 01:53 PM
Last Post: leoahum
  fibonacci ***Time limit exceeded*** frequency 18 10,221 Nov-29-2018, 09:03 PM
Last Post: frequency
  'Time Limit Exceeded' Problem bkpee3 2 5,444 Nov-14-2018, 03:51 AM
Last Post: bkpee3
  variable loop depth Skaperen 5 4,345 Jul-18-2018, 02:48 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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