Yes, it is possible to display the Pandas DataFrame on the main root window using grid
so that it aligns with other widgets. To achieve this, you can follow these steps:
- Create a new frame inside the main root window where you want to display the DataFrame.
- Instead of using
Toplevel
, use the new frame to display the DataFrame.
- Use
grid
layout manager to place the new frame in the desired position within the root window.
Here's the modified code:
import tkinter as tk
from pandastable import Table # Assuming you are using pandastable to display DataFrames
def calculate_button(x, y, n, m):
global results
results = funct(x, y, n, m)
print(results)
# Create a new frame inside the root window to display the DataFrame
results_frame = tk.Frame(root) # Replace 'root' with the actual name of your main root window
results_frame.grid(row=row_number, column=column_number, padx=10, pady=10) # Adjust row and column number as per your requirement
# Create the PandasTable inside the new frame
results_window = Table(results_frame, dataframe=results, showtoolbar=False, showstatusbar=False)
results_window.show()
# Create your Tkinter main root window
root = tk.Tk()
# Add other widgets and layouts using grid or pack as necessary
# Example usage of the calculate_button function
calculate_button(x, y, n, m)
# Start the main event loop
root.mainloop()
Make sure to replace 'root'
with the actual name of your main root window, and adjust the row
and column
numbers in results_frame.grid
according to where you want the DataFrame to be displayed.
With these changes, the DataFrame will be displayed inside the new frame within the main root window using the grid
layout manager.