Python Forum
[Tkinter] Troubles with accessing attr from other class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Troubles with accessing attr from other class
#1
Hi Guys,

I would like to make a "big button" which would load data in several tabs in my app.
In order to do this, i wanted create a function which would load 2nd part of the data, however, i can't access it.. i don't know why.

There is no problem to call the function, in that particular way it is working, but i would like to access it from other tab and then i can't make it.
    def test(self):
         
        self.historical_entry_market.insert(0, "asd")
I tried to run:
    def test(self):
         
        Comments_Tab(self).historical_entry_market.insert(0, "asd")
However it is not working..


Below are the codes for files
MAIN.py
import tkinter as tk
from tkinter.ttk import *
import pandas as pd
from rents import Rents_Tab
from comments import Comments_Tab

class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent
        self.parent.geometry("700x700")
        
        self.notebook = Notebook(self)
        self.notebook.pack(fill="both", expand=True)
        
        #Tab name
        page1 = Rents_Tab(self.notebook)
        self.notebook.add(page1, text="Rents")
        page2 = Comments_Tab(self.notebook)
        self.notebook.add(page2, text="Comments")



if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack(side="top", fill="both", expand=True)
    root.mainloop()
comments.py
import tkinter as tk
from tkinter.ttk import *
import pandas as pd


class Comments_Tab(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        
        #Headers
        self.header = Label(self, text="New Cycle(Current) ")
        self.header.grid(row=0, column=2)

        
        self.entry_label_market = Label(self, text="Market Trend: ")
        self.entry_label_market.grid(row=1, column=1)
        self.entry_market = Entry(self, width=30)
        self.entry_market.grid(row=1, column=2)
        
        self.entry_label_location = Label(self, text="Trend: ")
        self.entry_label_location.grid(row=2, column=1)
        self.entry_location = Entry(self, width=30)
        self.entry_location.grid(row=2, column=2)

        self.entry_label_survey = Label(self, text="Sources: ")
        self.entry_label_survey.grid(row=3, column=1)
        self.entry_survey = Entry(self, width=30)
        self.entry_survey.grid(row=3, column=2)
        
        ### Historical Data
        #Headers
        self.historical_header = Label(self, text="Historical ")
        self.historical_header.grid(row=0, column=3)
        #Labels
        self.historical_entry_market = Entry(self, width=30)
        self.historical_entry_market.grid(row=1, column=3)       

        self.historical_entry_location = Entry(self, width=30)
        self.historical_entry_location.grid(row=2, column=3)

        self.historical_entry_survey = Entry(self, width=30)
        self.historical_entry_survey.grid(row=3, column=3)
        
        #Buttons
        test_button = Button(self, text="Show Data", command=lambda: Comments_Tab.test(self))
        test_button.grid(row=5, column=3)
        
    def test(self):
        
        Comments_Tab(self).historical_entry_market.insert(0, "asd")
Reply


Messages In This Thread
[Tkinter] Troubles with accessing attr from other class - by zarize - Aug-20-2020, 07:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,490 Dec-14-2022, 08:01 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,154 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] Redirecting all print statements from all functions inside a class to Tkinter Anan 1 2,668 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  tkinter moving an class object with keybinds gr3yali3n 5 3,301 Feb-10-2021, 09:13 PM
Last Post: deanhystad
  [Tkinter] Use function from other class (Tkinter) zarize 8 4,876 Aug-17-2020, 09:47 AM
Last Post: zarize
  Unable fetch fucntion data in class in tkinter jenkins43 2 3,903 Nov-30-2019, 09:47 PM
Last Post: jenkins43
  Tkinter Class pythonenthusiast2 1 2,647 Nov-24-2019, 03:51 AM
Last Post: Larz60+
  tkinter button not accessing the command when clicked jhf2 1 3,599 Nov-23-2019, 10:17 PM
Last Post: DT2000
  Tkinter Gui ScrolledText Insert From Different Class whisperquiet 1 4,348 Jan-08-2019, 09:25 PM
Last Post: Larz60+
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 11,017 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

User Panel Messages

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