Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:56:24+00:00 2026-05-24T15:56:24+00:00

I am using tkinter to write a simple GUI program to plot figure of

  • 0

I am using tkinter to write a simple GUI program to plot figure of some data, the plot function is realized using matplotlib module, here is my simplified code:

#!/usr/bin/env python
import Tkinter, tkFileDialog, tkMessageBox
from plot_core import berplot

class BerPlotTk(Tkinter.Frame):
    def __init__ (self, master = None):
        Tkinter.Frame.__init__(self, master, width = 500, height = 200)
        self.fullfilenames = [] # filename with path            
        self.master = master   
        self.CreateWidgets()

    def CreateWidgets(self):
        # other widgets...

        # Buttons
        self.button_sel = Tkinter.Button(self, text = "Open", command = self.Open)                          
        self.button_sel.grid(column = 0, row = 7, sticky = "EW")
        self.button_plot = Tkinter.Button(self, text = "Plot", command = self.Plot)                                              
        self.button_plot.grid(column = 2, row = 7, sticky = "EW")            
        self.button_exit = Tkinter.Button(self, text = "Exit", command = self.top.quit)                                              
        self.button_exit.grid(column = 3, row = 7, sticky = "EW")

    def Open(self):
        input_filenames = tkFileDialog.askopenfilename(parent = self.master,
                                    title = "Select the log file")
        self.fullfilenames = list(self.tk.splitlist(input_filenames))

    def Plot(self):
        berplot(self.fullfilenames)            


if __name__ == "__main__":
    root = Tkinter.Tk()
    app = BerPlotTk(root)
    root.mainloop()
    root.destroy()

berplot() is a function in another python module as:

from matplotlib.pyplot import * 
def berplot(filelist):

    # retrieve data x, y from the log file
    # ...        
    ber = semilogy(x, y)
    # ...
    show()
    return 1

The program can work, when I open the data file and click “Plot” button, it will create a figure window(by the matplotlib), but the GUI can not continue to process before I close the figure window. However, I want to continue to draw next figure while keeping current one, How can I realize this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:56:25+00:00Added an answer on May 24, 2026 at 3:56 pm

    you can embed matplotlib figure in to Tk GUI:

    import matplotlib
    matplotlib.use('TkAgg')
    
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.figure import Figure
    import Tkinter as Tk
    
    class TkPlot(Tk.Frame):
        def __init__ (self, master = None):
            Tk.Frame.__init__(self, master, width = 500, height = 200)
            self.CreateWidgets()
    
        def CreateWidgets(self):
            self.button = Tk.Button(root, text="Plot", command=self.Plot)
            self.button.pack()
            self.figure = Figure(figsize=(5,4), dpi=100)
    
            canvas = FigureCanvasTkAgg(self.figure, master=root)
            canvas.show()
            canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    
            toolbar = NavigationToolbar2TkAgg( canvas, root )
            toolbar.update()
            canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    
        def Plot(self):
            a = self.figure.add_subplot(111)
            t = arange(0.0,3.0,0.01)
            s = sin(2*pi*t)
            a.plot(t,s)
            self.figure.canvas.draw()
    
    if __name__ == "__main__":
        root = Tk.Tk()
        app = TkPlot(root)
        root.mainloop()
    

    http://matplotlib.sourceforge.net/examples/user_interfaces/index.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a simple GUI program in python using Tkinter. Let's call this program
I'm new to Python and I'm trying to create a simple GUI using Tkinter.
I have written a simple GUI in Python using the Tkinter library. This GUI
I'm writing a Python program with a GUI built with the Tkinter module. I'm
I'm creating a simple GUI app using Tkinter with Python, but I'm having problems
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
I'm using tkinter with Python to create a user interface for a program that
How can I place an image in a Tkinter GUI using the python standard
I am writing an application in Python using Tkinter to manage my GUI. There
I've been writing a long GUI in Python using Tkinter. One thing that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.