Home > Software design >  Matplotlib crashes my GUI tkinter application
Matplotlib crashes my GUI tkinter application

Time:04-15

I have a GUI Tkinter Python application which I built. However, I am struggling with the plots. I am not willing to plot inside it, but only to generate the plots and save them. The problem is that when I click my button to generate the plots, the Tkinter GUI just crashes.

Note that I have tried every solution I managed to find on the web regarding this issue. Please help me. Thanks in advance.

from __future__ import print_function
import ast
import json

import matplotlib

matplotlib.use("TkAgg")
from matplotlib import pyplot as plt

import pandas as pd
import seaborn as sns


`if __name__ == "__main__":`
screen = Tk()
screen.title('My App')
screen.geometry('800x800')
screen.config(bg='#453')

f = ('sans-serif', 13)
btn_font = ('sans-serif', 10)
bgcolor = '#3399ff'

# frames
frame = Frame(screen, padx=20, pady=20, bg=bgcolor)
frame.pack(expand=True, fill=BOTH)

# label widgets
Label(
    frame,
    text="Company",
    font=f,
    bg=bgcolor
).grid(row=0, column=0, sticky='w')

Label(
    frame,
    text="Source Date",
    font=f,
    bg=bgcolor
).grid(row=1, column=0, sticky='w')

Label(
    frame,
    text="Destination Date",
    font=f,
    bg=bgcolor
).grid(row=2, column=0, sticky='w')

# entry widgets
comp = Entry(frame, width=21, font=f)
comp.grid(row=0, column=1)

src_date = DateEntry(frame, selectmode='day', date_pattern='dd/mm/yyyy', width=19, font=f)

src_date.grid(row=1, column=1)

dest_date = DateEntry(frame, selectmode='day', date_pattern='dd/mm/yyyy', width=19, font=f)
dest_date.grid(row=2, column=1)

clear_dates(src_date, dest_date)

# Buttons & Actions
btn_frame = Frame(frame, bg=bgcolor)
btn_frame.grid(columnspan=2, pady=(50, 0))

# default inputs for testing
comp.insert(0, 'Enter Company Name')

# action buttons

submit_btn = Button(
    btn_frame,
    text='Generate Word',
    command=validate_company_and_generate_report,  # generate
    font=btn_font,
    padx=10,
    pady=5
)
submit_btn.pack(side=LEFT, expand=True, padx=(15, 0))

clear_btn = Button(
    btn_frame,
    text='Clear',
    command=clear_inputs(comp, src_date, dest_date),
    font=btn_font,
    padx=10,
    pady=5,
    width=7
)
clear_btn.pack(side=LEFT, expand=True, padx=15)

exit_btn = Button(
    btn_frame,
    text='Exit',
    command=lambda: screen.destroy(),
    font=btn_font,
    padx=10,
    pady=5
)
exit_btn.pack(side=LEFT, expand=True)

screen.mainloop()

The command executed upon clicking the "Generate Word" button is essentially plots various charts.Not more than that.

CodePudding user response:

Solved by using another thread for matplotlib!

  • Related