为什么我的表格控件(Glade/Python)不起作用?

发布于 2025-02-02 14:39:18 字数 22050 浏览 4 评论 0原文

我已经开发了一种简单的GLADE形式,我的意思是用Python-3.10操纵。

我以为我的代码正确,但是控件没有响应。 (特别是按钮)。

如果有人能提供帮助,我将是很多义务。我以为主要GUI类中的“ Connect_Symbols(self)”会照顾好它,但我仍然缺少一些东西。

这是程序:

#!/usr/bin/env python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import sys
import os

builder = Gtk.Builder()

class GUI:

    def __init__ (self):
        builder.add_from_file('Form-10a.glade')
        builder.connect_signals(self)
        self.Pindir = None
        self.Poutdir = None
        self.Psortby = 'type'
        self.Preport = 'False'
        self.Pverbose = 'True'
        window = builder.get_object('window1')
        window.show_all()
        #
    def onSubmitButtonCli#cked(self, button):
        inputdir = builder.get_object('inputdir').get_property('text')
        print(f'inputdir = {inputdir}')
        tv = os.path.exists(inputdir)
        if (tv == False):
            print(inputdir, "is not a vaild directory, try again.")
        else:    
            self.Pindir = inputdir
        
        outputdir = builder.get_object('outputdir').get_property('text')
        print(f'outputdir = {outputdir}')
        self.Poutdir=outputdir
        
        name_button = builder.get_object('NameButton')
        #print('[NameButton] active:', name_button.get_active())
        #print('[NameButton] group :', name_button.get_group())
        for item in name_button.get_group():
            name  = item.get_name()
            truth_value = item.get_active()
            print(name, '=', truth_value)
            if (truth_value == True):
                self.Psortby = name
                i = self.Psortby.index('Button')
                self.Psortby=self.Psortby[0:i]
            
        report_button = builder.get_object('ReportY')
        for item in report_button.get_group():
            name = item.get_name()
            truth_value = item.get_active()
            print(name, '=' , truth_value)
            self.Preport = truth_value


        verbose_button = builder.get_object('VerboseY')
        for item in verbose_button.get_group():
            name = item.get_name()
            truth_value = item.get_active()
            print(name, '=', truth_value)
            #            tv = ((truth_value=='True')?1:0)
            self.Pverbose = truth_value

        with open('scripts-search.conf','w') as w:
            w.write('[Main]\n')
            outputdata = 'inputdir: ' + self.Pindir + '\n'
            w.write(outputdata)
            outputdata = 'outputdir: ' + self.Poutdir + '\n'
            w.write(outputdata)
            outputdata = 'sortby: ' + str(self.Psortby) + '\n'
            w.write(outputdata)
            outputdata = 'report: ' +str(self.Preport) + '\n'
            w.write(outputdata)
            outputdata = 'verbose: ' + str(self.Pverbose) + '\n'
            w.write(outputdata)
            w.write('\n')
        Gtk.main_quit()
                    
    def onDestroy(self,menuitem):
        Gtk.main_quit()

    def onQuitButtonClicked(self,button):
        Gtk.main_quit()
        
        
def main():
    while True:
        try:
            app = GUI()
            Gtk.main()
        except Exception as e:
            print ("Error!!")
            print (e.inst)
            Gtk.main_quit()

if __name__ == '__main__':
    rv = 0
    rv = main()
    sys.exit(rv)

而且,如果有人有兴趣,这里是form-10a.glade:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkWindow" id="window1">
    <property name="name">GtkWindow</property>
    <property name="can-focus">True</property>
    <property name="window-position">center-always</property>
    <property name="default-width">380</property>
    <property name="default-height">200</property>
    <property name="destroy-with-parent">True</property>
    <property name="type-hint">dialog</property>
    <property name="gravity">north-east</property>
    <signal name="destroy" handler="onDestroy" swapped="no"/>
    <child>
      <!-- n-columns=2 n-rows=7 -->
      <object class="GtkGrid">
        <property name="visible">True</property>
        <property name="can-focus">True</property>
        <child>
          <object class="GtkLabel">
            <property name="name">label1</property>
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <property name="margin-left">3</property>
            <property name="margin-right">3</property>
            <property name="margin-start">3</property>
            <property name="margin-end">3</property>
            <property name="margin-top">3</property>
            <property name="margin-bottom">3</property>
            <property name="label" translatable="yes">Scripts Search - Enter Parameters</property>
            <property name="justify">fill</property>
            <attributes>
              <attribute name="font-desc" value="Serif 12"/>
              <attribute name="style" value="normal"/>
              <attribute name="weight" value="normal"/>
              <attribute name="variant" value="normal"/>
              <attribute name="stretch" value="normal"/>
              <attribute name="scale" value="1"/>
            </attributes>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">0</property>
            <property name="width">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="GtkWindow">
            <property name="name">GtkWindow</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">
</property>
            <property name="justify">center</property>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Directory to search:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Direcotry for output:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Sort by:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">3</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Printed Report?  (y/n):</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">4</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Verbose? (y/n):</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">5</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="inputdir">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="text" translatable="yes">/usr/bin</property>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="outputdir">
            <property name="name">outputdir</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="text">/home/baz/misc/docs</property>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkButtonBox" id="inputdi">
            <property name="name">inputdir</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="layout-style">start</property>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
            <child>
              <placeholder/>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=3 n-rows=1 -->
          <object class="GtkGrid" id="radiobutton">
            <property name="name">radiobutton</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <child>
              <object class="GtkRadioButton" id="NameButton">
                <property name="label" translatable="yes">Name      </property>
                <property name="name">NameButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="SizeButton">
                <property name="label" translatable="yes">Size      </property>
                <property name="name">SizeButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="draw-indicator">True</property>
                <property name="group">NameButton</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="TypeButton">
                <property name="label" translatable="yes">Type  </property>
                <property name="name">TypeButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="draw-indicator">True</property>
                <property name="group">NameButton</property>
              </object>
              <packing>
                <property name="left-attach">2</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">3</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkRadioButton" id="ReportY">
                <property name="label" translatable="yes">Y             </property>
                <property name="name">ReportY</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="ReportN">
                <property name="label" translatable="yes">N            </property>
                <property name="name">ReportN</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
                <property name="group">ReportY</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">4</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkRadioButton" id="VerboseY">
                <property name="label" translatable="yes">Y             </property>
                <property name="name">VerboseY</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="VerboseN">
                <property name="label" translatable="yes"></property>
                <property name="name">VerboseN</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
                <property name="group">VerboseY</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">5</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkButton" id="SaveButton">
                <property name="label" translatable="yes">Save</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="QuitButton">
                <property name="label" translatable="yes">Quit WIthout Saving</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
                <signal name="clicked" handler="onQuitButtonClicked" swapped="no"/>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">6</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="SubmitButtton">
            <property name="label" translatable="yes">Submit</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <signal name="clicked" handler="onSubmitButtonClicked" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">6</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

I have developed a simple glade form that I mean to manipulate with python-3.10.

I thought I had the code right, but the controls just do not respond. (in particular, the buttons).

If anyone can help, I would be much obliged. I thought the "connect_symbols(self)" in the main Gui class would have taken care of it, but I'm still missing something.

Here is the program:

#!/usr/bin/env python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import sys
import os

builder = Gtk.Builder()

class GUI:

    def __init__ (self):
        builder.add_from_file('Form-10a.glade')
        builder.connect_signals(self)
        self.Pindir = None
        self.Poutdir = None
        self.Psortby = 'type'
        self.Preport = 'False'
        self.Pverbose = 'True'
        window = builder.get_object('window1')
        window.show_all()
        #
    def onSubmitButtonCli#cked(self, button):
        inputdir = builder.get_object('inputdir').get_property('text')
        print(f'inputdir = {inputdir}')
        tv = os.path.exists(inputdir)
        if (tv == False):
            print(inputdir, "is not a vaild directory, try again.")
        else:    
            self.Pindir = inputdir
        
        outputdir = builder.get_object('outputdir').get_property('text')
        print(f'outputdir = {outputdir}')
        self.Poutdir=outputdir
        
        name_button = builder.get_object('NameButton')
        #print('[NameButton] active:', name_button.get_active())
        #print('[NameButton] group :', name_button.get_group())
        for item in name_button.get_group():
            name  = item.get_name()
            truth_value = item.get_active()
            print(name, '=', truth_value)
            if (truth_value == True):
                self.Psortby = name
                i = self.Psortby.index('Button')
                self.Psortby=self.Psortby[0:i]
            
        report_button = builder.get_object('ReportY')
        for item in report_button.get_group():
            name = item.get_name()
            truth_value = item.get_active()
            print(name, '=' , truth_value)
            self.Preport = truth_value


        verbose_button = builder.get_object('VerboseY')
        for item in verbose_button.get_group():
            name = item.get_name()
            truth_value = item.get_active()
            print(name, '=', truth_value)
            #            tv = ((truth_value=='True')?1:0)
            self.Pverbose = truth_value

        with open('scripts-search.conf','w') as w:
            w.write('[Main]\n')
            outputdata = 'inputdir: ' + self.Pindir + '\n'
            w.write(outputdata)
            outputdata = 'outputdir: ' + self.Poutdir + '\n'
            w.write(outputdata)
            outputdata = 'sortby: ' + str(self.Psortby) + '\n'
            w.write(outputdata)
            outputdata = 'report: ' +str(self.Preport) + '\n'
            w.write(outputdata)
            outputdata = 'verbose: ' + str(self.Pverbose) + '\n'
            w.write(outputdata)
            w.write('\n')
        Gtk.main_quit()
                    
    def onDestroy(self,menuitem):
        Gtk.main_quit()

    def onQuitButtonClicked(self,button):
        Gtk.main_quit()
        
        
def main():
    while True:
        try:
            app = GUI()
            Gtk.main()
        except Exception as e:
            print ("Error!!")
            print (e.inst)
            Gtk.main_quit()

if __name__ == '__main__':
    rv = 0
    rv = main()
    sys.exit(rv)

And, if anyone is interested, here is Form-10a.glade:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkWindow" id="window1">
    <property name="name">GtkWindow</property>
    <property name="can-focus">True</property>
    <property name="window-position">center-always</property>
    <property name="default-width">380</property>
    <property name="default-height">200</property>
    <property name="destroy-with-parent">True</property>
    <property name="type-hint">dialog</property>
    <property name="gravity">north-east</property>
    <signal name="destroy" handler="onDestroy" swapped="no"/>
    <child>
      <!-- n-columns=2 n-rows=7 -->
      <object class="GtkGrid">
        <property name="visible">True</property>
        <property name="can-focus">True</property>
        <child>
          <object class="GtkLabel">
            <property name="name">label1</property>
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <property name="margin-left">3</property>
            <property name="margin-right">3</property>
            <property name="margin-start">3</property>
            <property name="margin-end">3</property>
            <property name="margin-top">3</property>
            <property name="margin-bottom">3</property>
            <property name="label" translatable="yes">Scripts Search - Enter Parameters</property>
            <property name="justify">fill</property>
            <attributes>
              <attribute name="font-desc" value="Serif 12"/>
              <attribute name="style" value="normal"/>
              <attribute name="weight" value="normal"/>
              <attribute name="variant" value="normal"/>
              <attribute name="stretch" value="normal"/>
              <attribute name="scale" value="1"/>
            </attributes>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">0</property>
            <property name="width">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="GtkWindow">
            <property name="name">GtkWindow</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">
</property>
            <property name="justify">center</property>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Directory to search:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Direcotry for output:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Sort by:</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">3</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Printed Report?  (y/n):</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">4</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="label" translatable="yes">Verbose? (y/n):</property>
            <property name="justify">right</property>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">5</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="inputdir">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="text" translatable="yes">/usr/bin</property>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkEntry" id="outputdir">
            <property name="name">outputdir</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="text">/home/baz/misc/docs</property>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkButtonBox" id="inputdi">
            <property name="name">inputdir</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="layout-style">start</property>
            <signal name="destroy" handler="onDestroy" swapped="no"/>
            <child>
              <placeholder/>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">1</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=3 n-rows=1 -->
          <object class="GtkGrid" id="radiobutton">
            <property name="name">radiobutton</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <child>
              <object class="GtkRadioButton" id="NameButton">
                <property name="label" translatable="yes">Name      </property>
                <property name="name">NameButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="SizeButton">
                <property name="label" translatable="yes">Size      </property>
                <property name="name">SizeButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="draw-indicator">True</property>
                <property name="group">NameButton</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="TypeButton">
                <property name="label" translatable="yes">Type  </property>
                <property name="name">TypeButton</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="draw-indicator">True</property>
                <property name="group">NameButton</property>
              </object>
              <packing>
                <property name="left-attach">2</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">3</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkRadioButton" id="ReportY">
                <property name="label" translatable="yes">Y             </property>
                <property name="name">ReportY</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="ReportN">
                <property name="label" translatable="yes">N            </property>
                <property name="name">ReportN</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
                <property name="group">ReportY</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">4</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkRadioButton" id="VerboseY">
                <property name="label" translatable="yes">Y             </property>
                <property name="name">VerboseY</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="VerboseN">
                <property name="label" translatable="yes"></property>
                <property name="name">VerboseN</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">False</property>
                <property name="active">True</property>
                <property name="draw-indicator">True</property>
                <property name="group">VerboseY</property>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">5</property>
          </packing>
        </child>
        <child>
          <!-- n-columns=2 n-rows=1 -->
          <object class="GtkGrid">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <child>
              <object class="GtkButton" id="SaveButton">
                <property name="label" translatable="yes">Save</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
              </object>
              <packing>
                <property name="left-attach">0</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="QuitButton">
                <property name="label" translatable="yes">Quit WIthout Saving</property>
                <property name="visible">True</property>
                <property name="can-focus">True</property>
                <property name="receives-default">True</property>
                <signal name="clicked" handler="onQuitButtonClicked" swapped="no"/>
              </object>
              <packing>
                <property name="left-attach">1</property>
                <property name="top-attach">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left-attach">1</property>
            <property name="top-attach">6</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="SubmitButtton">
            <property name="label" translatable="yes">Submit</property>
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <signal name="clicked" handler="onSubmitButtonClicked" swapped="no"/>
          </object>
          <packing>
            <property name="left-attach">0</property>
            <property name="top-attach">6</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作业与我同在 2025-02-09 14:39:18

我对Python有点生锈,但是当我尝试您的代码和GLADE文件时,我的行为会有所不同。每当我单击按钮或尝试关闭应用程序时,新窗户都会不断产卵。我不得不手动杀死该应用程序。我为使事情工作所做的小修改是通过删除“ true:”测试来简化主块。

def main():
    try:
        app = GUI()
        Gtk.main()
    except Exception as e:
        print ("Error!!")
        print (e.inst)
        Gtk.main_quit()

之后,“提交”按钮产生了输出,并且“不保存”按钮工作了。我在您的GLADE文件中注意到,您还没有为“保存”按钮设置信号。

希望有帮助。

问候。

I am a bit rusty with Python, but when I tried out your code and glade file, I got a different behavior. Whenever I clicked on buttons or tried to close down the application, new windows kept spawning. I had to manually kill the application. The small revision I did to get things to work was to simplify the main block by removing the "while True:" test.

def main():
    try:
        app = GUI()
        Gtk.main()
    except Exception as e:
        print ("Error!!")
        print (e.inst)
        Gtk.main_quit()

After that, the "Submit" button produced output and the "Quit Without Saving" button worked. I noticed in your glade file that you had no signal set up yet for the "Save" button.

Hope that helps.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文