Calling Tkinter Objects from Another File

For objects you want to access outside of the class, you must make them instance attributes of the class.

For example, you wouldn’t use global like in your example. The use of global largely defeats the purpose of using classes. Instead, you do it like this:

class SneakerGuide(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        
        self.stockXURLInput = Entry(sneakerBasicDetails)
        self.stockXURLInput.grid(row=5, column=1)

To get the value out of the entry, all you need is a reference to the instance of the class.

root = tk.Tk()
...
guide = SneakerGuide(root)
...
print(f"The url is {guide.stockXURLInput.get9)}")

This isn’t anything unique to tkinter, this is how all python objects work.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top