I have a simple tkinter app that plots a sine curve. The problem I am facing is that when I press the PLOT button, original root window shrinks in size. I want to keep the window size fixed, irrespective of pressing the PLOT button or not. what shall I do?
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
# Function to handle button click event
def plot_sine_wave():
# Generate random data for the sine wave
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x + np.random.uniform(-0.5, 0.5))
# Create a new window for the plot
plot_window = tk.Toplevel(root)
plot_window.title("Random Sine Wave Plot")
# Create the plot
plt.figure()
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Random Sine Wave")
plt.grid(True)
# Display the plot in the new window
canvas = FigureCanvasTkAgg(plt.gcf(), master=plot_window)
canvas.draw()
canvas.get_tk_widget().pack()
# Create the main window
root = tk.Tk()
root.title("Sine Wave Plot")
root.geometry("200x100")
root.resizable(False, False) # Set resizable attribute to False
# Create the 'PLOT' button
plot_button = tk.Button(root, text="PLOT", command=plot_sine_wave)
plot_button.pack(pady=20)
# Run the Tkinter event loop
root.mainloop()