The thing I want is as blow.
- Click the button ’30d graph’
- A new window appears and the graph is on the new window
Reality is
- In jupyter notebook, all codings are possible
2-1. Push shift + enter
2-2. Input ‘Load VACS spec’ file and ‘Load Distribution’ file.
2-3. Click the ’30d graph’ button.
2-4. A new window is occurs and the graph is shown on the new window well.
-
Put out the .exe file from anaconda prompt.
-
Turn on the .exe program
-
2-2.~2-4. repeat
-
A new window is occurs BUT the graph is not shown
Here’s my python code and…anyone who professional to python help me…please
I have suffered from this problem during 2 weeks…
import tkinter as tk
from tkinter import filedialog
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pandas as pd
window = tk.Tk()
window.geometry("500x300")
def load_spec():
global xx
global yy
global xxx
global yyy
global xxxx
global yyyy
spec_window = tk.Toplevel(window)
file_path = filedialog.askopenfilename()
file_name_label=tk.Label(spec_window, text = "Selected File:" + file_path)
file_name_label.pack()
df = pd.read_excel(file_path)
xx = df.iloc[:,0].tolist()
yy = df.iloc[:,1].tolist()
xxx = df.iloc[:,2].tolist()
yyy = df.iloc[:,3].tolist()
xxxx = df.iloc[:,4].tolist()
yyyy = df.iloc[:,5].tolist()
def load_distribution():
global x1
global y1
global x2
global y2
global x3
global y3
distribution_window = tk.Toplevel(window)
file_path = filedialog.askopenfilename()
file_name_label=tk.Label(distribution_window, text = "Selected File:" + file_path)
file_name_label.pack()
df = pd.read_excel(file_path)
x1 = df.iloc[:,0].tolist()
y1 = df.iloc[:,1].tolist()
x2 = df.iloc[:,2].tolist()
y2 = df.iloc[:,3].tolist()
x3 = df.iloc[:,4].tolist()
y3 = df.iloc[:,5].tolist()
def draw_30d_graph():
fig=plt.figure()
graph_window = tk.Toplevel(window)
graph_window.geometry("500x300")
plt.savefig('test.png')
plt.plot(x1,y1,'o',label='30d')
plt.plot(xx,yy,label='30d spec')
plt.title("30d Graph")
plt.xlabel("du'")
plt.ylabel("dv'")
plt.legend()
canvas = FigureCanvasTkAgg(fig, master = graph_window)
canvas.draw()
canvas.get_tk_widget().pack()
def save_image():
file_path = filedialog.asksaveasfilename(defaultextension='.png')
fig.savefig(file_path)
save_button = tk.Button(graph_window,text="Save",command=save_image)
save_button.pack()
def draw_45d_graph():
fig=plt.figure()
graph_window = tk.Toplevel(window)
graph_window.geometry("500x300")
plt.savefig('test.png')
plt.plot(x2,y2,'o',label='45d')
plt.plot(xxx,yyy,label='45d spec')
plt.title("45d Graph")
plt.xlabel("du'")
plt.ylabel("dv'")
plt.legend()
canvas = FigureCanvasTkAgg(fig, master = graph_window)
canvas.draw()
canvas.get_tk_widget().pack()
def save_image():
file_path = filedialog.asksaveasfilename(defaultextension='.png')
fig.savefig(file_path)
save_button = tk.Button(graph_window,text="Save",command=save_image)
save_button.pack()
def draw_60d_graph():
fig=plt.figure()
graph_window = tk.Toplevel(window)
graph_window.geometry("500x300")
plt.savefig('test.png')
plt.plot(x3,y3,'o',label='60d')
plt.plot(xxxx,yyyy,label='60d spec')
plt.title("60d Graph")
plt.xlabel("du'")
plt.ylabel("dv'")
plt.legend()
canvas = FigureCanvasTkAgg(fig, master = graph_window)
canvas.draw()
canvas.get_tk_widget().pack()
def save_image():
file_path = filedialog.asksaveasfilename(defaultextension='.png')
fig.savefig(file_path)
save_button = tk.Button(graph_window,text="Save",command=save_image)
save_button.pack()
button_30d = tk.Button(window, text="30d graph", command = draw_30d_graph)
button_45d = tk.Button(window, text="45d graph", command = draw_45d_graph)
button_60d = tk.Button(window, text="60d graph", command = draw_60d_graph)
button_load_vacs = tk.Button(window, text = "Load VACS spec", command = load_spec)
button_load_distribution = tk.Button(window, text = "Load Distribution", command = load_distribution)
button_30d.place(x=100, y=100)
button_45d.place(x=100, y=140)
button_60d.place(x=100, y=180)
button_load_vacs.place(x=100, y=20)
button_load_distribution.place(x=100, y=60)
window.mainloop()
꼬맹몬 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.