O
O
Oleksandr Shengera2021-10-25 12:47:05
Python
Oleksandr Shengera, 2021-10-25 12:47:05

Why does it throw the error NameError: name 'btn_click' is not defined?

import keyboard as key
import mouse
import time
import tkinter as tk
root=tk.Tk()
class aut:
  def btn_click(self):
    from tkinter import messagebox
    messagebox.showinfo(title="window", message="ENG:[hold v to autoclick][press Alt + 0 to close program]")

  def btn_click2(self):
    start_key = "v"
    stop_key = "Alt + 0"
    from tkinter import messagebox
    messagebox.showinfo(title="window", message="[AutoClicker started^_^]")
    while True:
      if key.is_pressed(start_key):
        time.sleep(0.11)
        mouse.double_click(button = "left")
      if key.is_pressed(stop_key):
        break

root["bg"]="#fafafa"
root.title("AutoClicker")
root.wm_attributes("-alpha", 1)
root.geometry("280x180")

root.resizable(width=False, height=False)
canvas=tk.Canvas(root, height=280, width=180)
canvas.pack()

frame=tk.Frame(root, bg="#C4AAB7")
frame.place(relwidth=1, relheight=1)
frame.place()

title=tk.Label(frame, text="by Oleksandr1337", bg="#C4AAB7", font="40")
title.pack()

btn=tk.Button(frame, text="instruction", bg="white", padx="65", pady="10", command=btn_click)
btn.pack()

btn2=tk.Button(frame, text="start AutoClicker", bg="white", padx="50", pady="10", command=self.btn_click2)
btn2.pack()
root.mainloop()

Gives an error NameError: name 'btn_click' is not defined.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
link_vrb, 2021-10-25
@Oleksandr1337

try to do without the class and remove the self arguments in the btn_click and btn_click2 functions, since the command does not accept functions with arguments

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question