第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

tkinter GUI 中的多個 matplotlib 實例

tkinter GUI 中的多個 matplotlib 實例

呼喚遠方 2023-10-18 10:49:05
我已經(jīng)構(gòu)建了簡單的 tkinter GUI?,F(xiàn)在,我嘗試可視化 3 個不同的圖形(通過使用不同的變量調(diào)用相同的函數(shù))并將它們放置在 GUI 的 3 個不同行中。當我這樣做時,我遇到了兩個問題:每次運行腳本(interface.py)時,我都會得到 2 個窗口 - GUI 和外部圖形的窗口。如何擺脫第二個?我無法可視化所有 3 個圖表。腳本在顯示第一個腳本后停止。我相信這是因為第一個圖在循環(huán)中工作(迭代大量數(shù)據(jù)點)。有什么解決辦法嗎?界面:# -*- coding: utf-8 -*-"""Created on Tue Oct  6 10:24:35 2020@author: Dar0"""from tkinter import * #import tkinter modulefrom visualizer import main #import module 'visualizer' that shows the graph in real timeclass Application(Frame):    ''' Interface for visualizing graphs, indicators and text-box. '''    def __init__(self, master):        super(Application, self).__init__(master)        self.grid()        self.create_widgets()        def create_widgets(self):        # Label of the 1st graph        Label(self,              text='Hook Load / Elevator Height / Depth vs Time'              ).grid(row = 0, column = 0, sticky = W)                # Graph 1 - Hook Load / Elevator Height / Depth vs Time        # button that displays the plot         #plot_button = Button(self,2        #                     command = main,        #                     height = 2,         #                     width = 10,         #                     text = "Plot"        #                     ).grid(row = 1, column = 0, sticky = W)                self.graph_1 = main(root, 1, 0)        # place the button         # in main window                 # Label of the 2nd graph        Label(self,              text = 'Hook Load / Elevator Height vs Time'              ).grid(row = 3, column = 0, sticky = W)                # Graph 2 - Hook Load / Elevator Height vs Time        self.graph_2 = main(root, 4, 0)                #Label of the 3rd graph        Label(self,              text = 'Hook Load vs Time'              ).grid(row = 6, column = 0, sticky = W)       
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經(jīng)驗 獲得超5個贊

關鍵是pyplot當你想在內(nèi)部繪制時不要使用,matplotlib.figure.Figure

下面是一個最小示例,它沿著我在您的代碼中看到的小部件繪制了 3 個獨立的圖表Text

import pandas as pd

import numpy as np

import tkinter as tk

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk

from matplotlib.figure import Figure

? ??

class Graph(tk.Frame):

? ? def __init__(self, master=None, title="", *args, **kwargs):

? ? ? ? super().__init__(master, *args, **kwargs)

? ? ? ? self.fig = Figure(figsize=(4, 3))

? ? ? ? ax = self.fig.add_subplot(111)

? ? ? ? df = pd.DataFrame({"values": np.random.randint(0, 50, 10)}) #dummy data

? ? ? ? df.plot(ax=ax)

? ? ? ? self.canvas = FigureCanvasTkAgg(self.fig, master=self)

? ? ? ? self.canvas.draw()

? ? ? ? tk.Label(self, text=f"Graph {title}").grid(row=0)

? ? ? ? self.canvas.get_tk_widget().grid(row=1, sticky="nesw")

? ? ? ? toolbar_frame = tk.Frame(self)

? ? ? ? toolbar_frame.grid(row=2, sticky="ew")

? ? ? ? NavigationToolbar2Tk(self.canvas, toolbar_frame)

? ??

root = tk.Tk()


for num, i in enumerate(list("ABC")):

? ? Graph(root, title=i, width=200).grid(row=num//2, column=num%2)


text_box = tk.Text(root, width=50, height=10, wrap=tk.WORD)

text_box.grid(row=1, column=1, sticky="nesw")

text_box.delete(0.0, "end")

text_box.insert(0.0, 'My message will be here.')


root.mainloop()

結(jié)果:

https://img1.sycdn.imooc.com/652f4aed0001eab106510607.jpg

查看完整回答
反對 回復 2023-10-18
  • 1 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號