I need to create a new window via Tkinter from another module in another class. However I face such issue:
__init__()
missing 1 required positional argument: df
I get the df
from another module to this class:
import tkinter as tk
import pandas as pd
class ITC():
def __init__(self, root, df):
self.df = df
self.root = root
print(self.df.head(2))
root = tk.Tk()
app = ITC(root)
root.geometry("1000x1000")
root.mainloop()
However, it does work without creating “root”:
class ITC:
def __init__(self, root, df):
self.df = df
self.root = root
print(self.df.head(2))
4
To address the issue of creating a new Tkinter window from another module in another class, you can follow these steps:
Ensure the df parameter is provided: When creating an instance of the ITC class, make sure to provide the df parameter along with the root.
Modify the ITC class to handle the df parameter: The class should be designed to accept the df parameter in its init method.
Instantiate the ITC class with all required arguments: Ensure that you pass both root and df when creating the ITC object.
import tkinter as tk
import pandas as pd
class ITC:
def __init__(self, root, df):
self.df = df
self.root = root
print(self.df.head(2))
# Example usage
if __name__ == "__main__":
root = tk.Tk()
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
app = ITC(root, df)
root.geometry("1000x1000")
root.mainloop()
1