#๐ Simple Name Error, Can't Figure It Out
41 messages ยท Page 1 of 1 (latest)
@tepid owl
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
700 lines? really?
name the line where this error pops up, first
import tkinter as tk
from tkinter import ttk
from tkinter import *
...
line 181, in autowork
self.update_debt(3)
line 242, in update_debt
self.update_all_tabs()
line 639, in update_all_tabs
finance_tab.update_money_display()
^^^^^^^^^^^
NameError: name 'finance_tab' is not defined. Did you mean: 'FinanceTab'?
Time.update_time is also cool
yeah idk moving the update_all_tabs() function below the tab creation just creates another error, and for some reason the first tab "street" isn't returning an error at all
even though it's also created after the function is used
moving the function will not change anything
you need a variable defined at the time that a function is ran
use debugger and check where update_all_tabs is called, seems like it's called way before all these xxx_tab's are initialized
well the issue is the tab in the notebook system I'm trying to create, but attempting to create the tab before using the function also results in an error
but yeah repositioning the function is useless
class StreetTab(tk.Frame):
def __init__(self, notebook, update_all_tabs): ...
my IDE is telling me that notebook is unused in the init
The error is because of how you have things set up. StreetTab's __init__ calls autowork, autowork calls update_time, and update_time calls update_all_tabs. Granted, autowork is called in a delayed callback, but if it runs before finance_tab = has run, that will cause that error.
First, I don't see why you're passing that function around in the first place. update_all_tabs is a global function (not the problem, just odd).
Uh well I was having trouble getting variables synchronized across tabs
So I created a function that calls to update those variables across the tabs since each tab is a class
Unless you do a large refactor, you might just need to do something like give the Tab classes a start method that kicks off the after(self.autowork()) calls so you can control when update_all_tabs is called.
Like kinda delay it for a moment so it can get to the tab creation?
That's not great since that's effectively a second initializer that you need to remember to call, but I don't see how else you'd fix this with how the code is set up currently/
Yeah this is definitely a learning experience trying to throw it together for a simple idle game, it's all scope errors and this is my third attempt
I mean on like line 704, call each tab's start method after all the tabs have been created.
Actually, it seems like all the start method would need to do it change the state of autowork_enabled.
And then you'd just start that BooleanVar as False.
omg that worked
Actually, that might be an abuse of that state.
Ok, good. I'm glad. You're welcome.
Yeah big thanks, that was driving me crazy. Should I close this question out?
Might as well. You can always open another thread later if you need to.
Aight thanks again
Also, FYI, that site you linked to is kind of a pain to use since it loads lazily, which breaks search and scrolling. This would be better:
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
For future reference.
Bookmarked, appreciate it
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.