0

我创建了一个 gnome-builder python 项目。要更改项目的 GUI,我使用 Glade。现在我想添加 matplotlib 来构建一些图表。但问题是要更改 GUI,Glade 使用 XML 文件构建 GUI,我不知道如何将 matplotlib 图表添加到 xml 文件。这是我运行项目的 main.py 文件:


import sys
import gi

gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, Gio

from .window import CovidtrackingWindow


class Application(Gtk.Application):
    def __init__(self):
        super().__init__(application_id='org.example.App',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = CovidtrackingWindow(application=self)
        win.present()


def main(version):
    app = Application()
    return app.run(sys.argv)

这是由 Glade 生成的 window.py 和 window.ui 文件:


from gi.repository import Gtk


@Gtk.Template(resource_path='/org/example/App/window.ui')
class CovidtrackingWindow(Gtk.ApplicationWindow):
    __gtype_name__ = 'CovidtrackingWindow'

    label = Gtk.Template.Child()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <template class="CovidtrackingWindow" parent="GtkApplicationWindow">
    <property name="can_focus">False</property>
    <property name="default_width">600</property>
    <property name="default_height">300</property>
    <child type="titlebar">
      <object class="GtkHeaderBar" id="header_bar">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="title">CovidTracking</property>
        <property name="show_close_button">True</property>
      </object>
    </child>
    <child>
      <object class="GtkFixed" id="fixed1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkStack" id="stk1">
            <property name="width_request">745</property>
            <property name="height_request">452</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkFixed" id="news">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
              </object>
              <packing>
                <property name="name">news</property>
                <property name="title" translatable="yes">News</property>
              </packing>
            </child>
            <child>
              <object class="GtkFixed" id="infor">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
              </object>
              <packing>
                <property name="name">infor</property>
                <property name="title" translatable="yes">Infor</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkFixed" id="vaccine">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
              </object>
              <packing>
                <property name="name">vaccine</property>
                <property name="title" translatable="yes">Vaccine</property>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="y">40</property>
          </packing>
        </child>
        <child>
          <object class="GtkStackSwitcher" id="swtich1">
            <property name="width_request">100</property>
            <property name="height_request">40</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="stack">stk1</property>
          </object>
        </child>
      </object>
    </child>
  </template>
</interface>
4

0 回答 0