Aug-15-2020, 09:49 AM
Hi guys,
I would like to use function defined in main class, in another file/class - Rents.py/class Rents_tab(Frame)
MAIN.PY
Using command=Application().Load_Data) gives me output
or
Using command=Application(parent).Load_Data) gives me output
I would like to use function defined in main class, in another file/class - Rents.py/class Rents_tab(Frame)
MAIN.PY
import pandas as pd from tkinter import * from tkinter.ttk import * from rents import * class Application(Frame): def __init__(self, parent): Frame.__init__(self, parent) #set window size parent.geometry("1600x1600") #Set the header of application parent.title("My first application") self.notebook = Notebook(self) self.notebook.grid(row=1, column=1) #DETERMINING TAB NAMES comment_tab = Comments_tab(self.notebook) rents_tab = Rents_tab(self.notebook) #Assign tab names self.notebook.add(rents_tab, text="Rents") def Load_Data(self): excel_file_mhs = pd.read_csv(r'C:\Users\USER\Desktop\project_))\September 2019.csv', encoding='cp1252') contr_select = excel_file_mhs.loc[excel_file_mhs['Country Name']== self.entry_country.get()] loca_select = contr_select.loc[contr_select['Location Name']== self.entry_location.get()] final_select = loca_select.loc[loca_select['Survey Date'] == self.entry_survey.get()] return final_selectRents.py - In that file i want to use the function Load_Data()
import pandas as pd from tkinter import * from main import * from tkinter.ttk import * class Rents_tab(Frame): def __init__(self, parent): Frame.__init__(self, parent) entry_label_country = Label(self, text="Please provide country: ") entry_label_country.grid(row=1, column=1) entry_country = Entry(self, width=30) entry_country.grid(row=1, column=2) entry_country.insert(0, "Poland") #Default displayed text entry_label_location = Label(self, text="Please provide location: ") entry_label_location.grid(row=2, column=1) entry_location = Entry(self, width=30) entry_location.grid(row=2, column=2) entry_location.insert(0, "Warsaw") #Default displayed text entry_label_survey = Label(self, text="Survey Date: ") entry_label_survey.grid(row=3, column=1) entry_survey = Entry(self, width=30) entry_survey.grid(row=3, column=2) entry_survey.insert(0, "2019") #Default displayed text # #Buttons test_button = Button(self, text="Show Data", command=Application().Load_Data) test_button.grid(row=3, column=3)Could you please guide me, what i am doing wrong?
Using command=Application().Load_Data) gives me output
Error:TypeError: __init__() missing 1 required positional argument: 'parent'
Using command=Application(self).Load_Data)or
Using command=Application(parent).Load_Data) gives me output
Error:AttributeError: 'Rents_tab' object has no attribute 'geometry'