⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example-3.py

📁 Developing with Gnome一书examples例子代码
💻 PY
字号:
#!/usr/bin/env python# This program displays a couple checkboxes and shows how to change# button labels, how to make widgets sensitive or unsensitive, how to# determine if a checkbox is active, how to provide access keys for# quick keyboard navigation, how to pass other widgets to callbacks# besides the one that receives the event, and how to manually get gtk# to update widgets without returning to the main event loop.import gtkimport gtk.gladefrom time import sleepclass ExampleWindow:  def __init__(self, glade_file):    # Parse the glade file    self.main_window = gtk.glade.XML(glade_file)    # Get the necessary widgets    self.sensitivity_check_button = \      self.main_window.get_widget("SensitivityCheckButton")    self.ooh_tell_me = self.main_window.get_widget("OohTellMe")    self.quit_button = self.main_window.get_widget("QuitButton")    # Connect the appropriate callbacks...    self.main_window.signal_autoconnect(      {"sensitivity_toggled" : self.sensitivity_toggled,       "quit_handler"        : self.quit_handler,       "delete_handler"      : self.delete_handler}      )      def sensitivity_toggled(self, widget_object):    self.ooh_tell_me.set_sensitive( self.sensitivity_check_button.get_active() );      def quit_handler(self, extra):    # If the user checked the OohTellMe button, we need to do some work...    if self.ooh_tell_me.get_active():      # Change the checkbutton's label      self.ooh_tell_me.set_label("M_ock me")      # Since we don't return to the main event loop, we have to      # manually tell gtk+ to process the set_label change (and any      # other changes that require processing).  WARNING: This method      # is actually obsolete and apparently has potential problems,      # but I was working with an older version of pygtk and this is      # the only way that would work.  I was too lazy to try intalling      # a newer version that might account for the fact that the main      # loop has moved from gtk to glib.      while gtk.events_pending():        gtk.main_iteration(1)      # Mock the user and give them some time to notice the change      print "Ha ha, you fell for it!  ",      print "I will not tell you what that checkbutton does!"      sleep(1)    gtk.mainquit();      def delete_handler(self,event,widget_object):    self.quit_handler(widget_object)    # No other handlers need be called...    return gtk.TRUE;# Create the ExampleWindowwindow = ExampleWindow("example-3.glade")# start the event loopgtk.main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -