I have the button which have to show my graph by pressing. But it shows immediately when i run my programm. It works normaly if my parameters left
and height
for graph contains in the click_graph
fuction like this.
def click_graph():
left = [1, 2, 3, 4, 5]
height = [10, 24, 36, 40, 5]
plt.bar(left, height, width = 1, color = ['grey', 'black'])
plt.show()
But I want to do like this. (Full program)
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter.ttk import *
def click_graph(left, height):
plt.bar(left, height, width = 1, color = ['grey', 'black'])
plt.show()
def win(left, height):
root = tk.Tk()
button = tk.Button(root, text= "Graph",command=click_graph(left, height))
button.pack()
button.place(x=10, y=100)
root.mainloop()
def main():
left = [1, 2, 3, 4, 5]
height = [10, 24, 36, 40, 5]
#opening window to press the button to show graph
win(left, height)
if __name__ == '__main__':
main()
source https://stackoverflow.com/questions/75464280/python-showing-the-graph-by-the-button-but-it-is-displayed-immediately-how-to
Comments
Post a Comment