Search code examples
pythontkintertabviewcustomtkinter

CustomTkinter TabView return final values


Using classes as recommended at https://github.com/TomSchimansky/CustomTkinter/wiki/CTkTabview#cgetattribute_name, I have added an overall OK button to be clicked when all widgets on all tabs have been populated.

In the example with only one widget below, the first printed response in MyTabView is the initial value of Something but I want to know the final response after all changes to all widgets.

import customtkinter as ctk

class MyTabView(ctk.CTkTabview):
    def __init__(self, master, **kwargs):
        super().__init__(master, **kwargs)

        self.add("tab 1")
        self.add("tab 2")

        self.Entry = ctk.CTkEntry(master=self.tab('tab 1'), textvariable=ctk.StringVar(value='Something'))
        self.Entry.grid(row=0, column=0, padx=20, pady=10)

        global response
        response = self.Entry.get()
        print(response)

class App(ctk.CTk):
    def __init__(self):
        super().__init__()

        self.tab_view = MyTabView(master=self)
        self.tab_view.grid(row=0, column=0, padx=20, pady=20)

        self.OKButton = ctk.CTkButton(self, text='OK', command=lambda: self.fn_okay())
        self.OKButton.grid(row=3, column=1, columnspan=1, padx=20, pady=20, sticky='ew')

    def fn_okay(self):
        response = MyTabView.Entry.get() # Gives a no attribute error
        print(response)

app = App()
app.mainloop()

How can I get all the final values within the App class when the OK button is clicked? My response = MyTabView.Entry.get() attempt results in a no attribute error but something is required here or the printed response will remain unchanged.

Another attempt was to watch variables [and call a function to record the latest values] in line with Tkinter: How can I check if any of the widgets of a specific frame have changed? but this does not seem to work with ctk.


Solution

  • @Tranbi posted a straight forward answer in the comments - use the instantiated Entry: self.tab_view.Entry.get()