Python Forum
What is this error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is this error?
#1
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1885, in __call__ return self.func(*args) File "D:\3. My folder\Projects\Programing\Python\VIRUS\Cute File.py", line 51, in <lambda> pop_btn = Button(popup, text = btn_txt, command = lambda : pop_2("Transfering Cash", "Your current cash is transferring to My account.\nYes this was a scam\nThe only way to stop this, is by clicking 'Ok'", "Ok", "260x85")) File "D:\3. My folder\Projects\Programing\Python\VIRUS\Cute File.py", line 36, in pop_2 popup.exit() AttributeError: 'function' object has no attribute 'exit'
def pop_2(title, message, btn_txt, geo):
    pop_2 = Tk()
    pop_2.title(title)
    pop_2.geometry(geo)
    popup.destroy()
Reply
#2
this is not the code that caused the error.
Here you have popup.destroy(), whatever popup is (according to traceback it's a function object), while the traceback shows popup.exit(). In any case popup is not a widget, but a function, according to traceback.
Post the full code, ideally minimal reproducible example, in python tags.

Also, post GUI related questions in the GUI section.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Jan-13-2021, 07:59 AM)buran Wrote: Also, post GUI related questions in the GUI section.
I thought that this was a gui problem,
But since it was a function error, I thought it wouldn't fit there!
Sorry, ill do it the next time.

Here's the full script,
from tkinter import *
import time

main = Tk()
main.title("Free Money!")
main.geometry("250x70")

def count_start():
    num = 10
    while num != 0:
        time.sleep(1)
        num = num - 1
        counter.config(text = "Auto close in : " + num)
        if num == 0:
            break

def popup_3(title, geo):
    popup = Tk()
    popup.title(title)
    popup.geometry(geo)

    message = Label(popup, text = "Your current balance is 00.00\nAuto Exit in : " + num)
    count_start()
    pop_btn = Button(popup, text = "Exit", command = popup.destroy)

    message.pack(pady = 5)
    pop_btn.pack(pady = 5)

def popup_2(title, message, btn_txt, geo):
    popup = Tk()
    popup.title(title)
    popup.geometry(geo)

    message = Label(popup, text = message)
    pop_btn = Button(popup, text = btn_txt, command = lambda : ok_3("Transfer Successful", "260x85"))

    message.pack(pady = 5)
    pop_btn.pack(pady = 5)

def popup(title, message, btn_txt, geo):
    popup = Tk()
    popup.title(title)
    popup.geometry(geo)

    message = Label(popup, text = message)
    pop_btn = Button(popup, text = btn_txt, command = lambda : ok_2("Transfering Cash", "Your current cash is transferring to My account.\nYes this was a scam\nThe only way to stop this, is by clicking 'Ok'", "Ok", "260x85"))

    message.pack(pady = 5)
    pop_btn.pack(pady = 5)

def ok_3(title, geo):
    popup.destroy()
    time.sleep(2)
    popup_3(title, geo)

def ok_2(title, message, btn_txt, geo):
    popup.destroy()
    time.sleep(2)
    popup_2(title, message, btn_txt, geo)


def ok_1(title, message, btn_txt, geo):
    main.destroy()
    time.sleep(2)
    popup(title, message, btn_txt, geo)


text = Label(main, text = "Press 'Ok' For Free Money!")
Ok_button = Button(main, text = "Ok", command = lambda : ok_1("Alert!", "You have been Attacked by a VIRUS!\nPress 'Ok' to kill the VIRUS.", "Ok", "250x80"))

text.pack(pady = 5)
Ok_button.pack(pady = 5)

main.mainloop()
I changed the script a bit!
Also this was made for fun.
Not for causing any damage to anyone.
Reply
#4
I see you have changed your script. Do you still face a problem? You are very liberal in reusing popup name.

Also, do you see the repeating code? You have several functions basically identical to one another - you need to restructure your code. DRY principle
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Jan-13-2021, 09:48 AM)buran Wrote: I see you have changed your script. Do you still face a problem? You are very liberal in reusing popup name.

Also, do you see the repeating code? You have several functions basically identical to one another - you need to restructure your code. DRY principle

Yes, My brain was soo under pressure when the errors struck.
I think ill look through the code when I'm less stressed!
Reply
#6
Don't use Tk() to make a window. Tk() is a special function that should only be called once for your entire application. It does return a window, but it also does a not of initialization for the application that is only supposed to happen once. So use Tk() to create the first window. Use Toplevel or messagebox to create additional windows.
import tkinter as tk
import tkinter.messagebox as messagebox

root = tk.Tk()
tk.Label(root, text='This is the first window', width=30, height=10).pack()

window2 = tk.Toplevel(root)
tk.Label(window2, text='This is the second window', width=30, height=10).pack()

window3 = messagebox.askquestion('Popup Window', 'This is a popup window')

tk.mainloop()
Oshadha likes this post
Reply


Forum Jump:

User Panel Messages

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