<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Ruby GTK 中的對話框 > 原文: [http://zetcode.com/gui/rubygtk/dialogs/](http://zetcode.com/gui/rubygtk/dialogs/) 在 Ruby GTK 編程教程的這一部分中,我們將介紹對話框。 對話框窗口或對話框是大多數現代 GUI 應用必不可少的部分。 對話被定義為兩個或更多人之間的對話。 在計算機應用中,對話框是一個窗口,用于與應用“對話”。 對話框用于輸入數據,修改數據,更改應用設置等。對話框是用戶與計算機程序之間進行通信的重要手段。 ## `MessageDialog` 消息對話框是方便的對話框,可向應用的用戶提供消息。 該消息包含文本和圖像數據。 ```rb #!/usr/bin/ruby ''' ZetCode Ruby GTK tutorial This example shows message dialogs. Author: Jan Bodnar Website: www.zetcode.com Last modified: May 2014 ''' require 'gtk3' class RubyApp < Gtk::Window def initialize super init_ui end def init_ui table = Gtk::Table.new 2, 2, true info = Gtk::Button.new :label => "Information" warn = Gtk::Button.new :label => "Warning" ques = Gtk::Button.new :label => "Question" erro = Gtk::Button.new :label => "Error" info.signal_connect "clicked" do on_info end warn.signal_connect "clicked" do on_warn end ques.signal_connect "clicked" do on_ques end erro.signal_connect "clicked" do on_erro end table.attach info, 0, 1, 0, 1 table.attach warn, 1, 2, 0, 1 table.attach ques, 0, 1, 1, 2 table.attach erro, 1, 2, 1, 2 add table set_title "Messages" signal_connect "destroy" do Gtk.main_quit end set_default_size 300, 100 set_window_position :center show_all end def on_info md = Gtk::MessageDialog.new :parent => self, :flags => :destroy_with_parent, :type => :info, :buttons_type => :close, :message => "Download completed" md.run md.destroy end def on_erro md = Gtk::MessageDialog.new :parent => self, :flags => :modal, :type => :error, :buttons_type => :close, :message => "Error loading file" md.run md.destroy end def on_ques md = Gtk::MessageDialog.new :parent => self, :flags => :destroy_with_parent, :type => :question, :buttons_type => :close, :message => "Are you sure to quit?" md.run md.destroy end def on_warn md = Gtk::MessageDialog.new :parent => self, :flags => :destroy_with_parent, :type => :warning, :buttons_type => :close, :message => "Unallowed operation" md.run md.destroy end end Gtk.init window = RubyApp.new Gtk.main ``` 在我們的示例中,我們將顯示四種消息對話框:信息,警告,問題和錯誤消息對話框。 ```rb info = Gtk::Button.new :label => "Information" warn = Gtk::Button.new :label => "Warning" ques = Gtk::Button.new :label => "Question" erro = Gtk::Button.new :label => "Error" ``` 我們有四個按鈕。 這些按鈕中的每個按鈕都會顯示不同類型的消息對話框。 ```rb def on_info md = Gtk::MessageDialog.new :parent => self, :flags => :destroy_with_parent, :type => :info, :buttons_type => :close, :message => "Download completed" md.run md.destroy end ``` 如果單擊信息按鈕,則會顯示信息對話框。 `Gtk::MessageDialog::INFO`指定對話框的類型。 `Gtk::MessageDialog::BUTTONS_CLOSE`指定要在對話框中顯示的按鈕的類型。 最后一個參數是顯示的消息。 該對話框使用`run`方法顯示。 程序員還必須調用`destroy`或`hide`方法。 ![Information message dialog](https://img.kancloud.cn/74/21/742112a7f15176073658fc9c6c6c5c62_223x158.jpg) ![Warning message dialog](https://img.kancloud.cn/fe/a5/fea5b886f9d1da77913bf4bbda804a4e_221x158.jpg) ![Question message dialog](https://img.kancloud.cn/bc/ec/bcec676671a0a8979f3ae54bac7be684_222x158.jpg) ![Error message dialog](https://img.kancloud.cn/9b/6d/9b6dc5423651e5cf580c077d84d08dcb_195x158.jpg) ## `AboutDialog` `AboutDialog`顯示有關應用的信息。 它可以顯示徽標,應用名稱,版本,版權,網站或許可證信息。 也有可能對作者,文檔撰寫者,翻譯者和藝術家予以贊揚。 ```rb #!/usr/bin/ruby ''' ZetCode Ruby GTK tutorial This example demonstrates the Gtk::AboutDialog dialog. Author: Jan Bodnar Website: www.zetcode.com Last modified: May 2014 ''' require 'gtk3' class RubyApp < Gtk::Window def initialize super set_title "About dialog" signal_connect "destroy" do Gtk.main_quit end init_ui set_default_size 300, 150 set_window_position :center show_all end def init_ui button = Gtk::Button.new :label => "About" button.set_size_request 80, 30 button.signal_connect "clicked" do on_clicked end fix = Gtk::Fixed.new fix.put button, 20, 20 add fix end def on_clicked about = Gtk::AboutDialog.new about.set_program_name "Battery" about.set_version "0.1" about.set_copyright "(c) Jan Bodnar" about.set_comments "Battery is a simple tool for battery checking" about.set_website "http://www.zetcode.com" begin logo = Gdk::Pixbuf.new :file => "batter.png" about.set_logo logo rescue IOError => e puts e puts "cannot load image" exit end about.run about.destroy end end Gtk.init window = RubyApp.new Gtk.main ``` 該代碼示例使用具有某些功能的`Gtk::AboutDialog`。 ```rb about = Gtk::AboutDialog.new ``` 我們創建`Gkt::AboutDialog`小部件。 ```rb about.set_program_name "Battery" about.set_version "0.1" about.set_copyright "(c) Jan Bodnar" ``` 在這里,我們指定名稱,版本和版權。 ```rb begin logo = Gdk::Pixbuf.new :file => "batter.png" about.set_logo logo rescue IOError => e puts e puts "cannot load image" exit end ``` 此行為對話框創建徽標。 執行一些錯誤檢查。 ![Gtk::AboutDialog](https://img.kancloud.cn/1d/4f/1d4f856ac950506995f93614ce10e18b_426x265.jpg) 圖:`Gtk::AboutDialog` ## `Gtk::FontSelectionDialog` `Gtk::FontSelectionDialog`是用于選擇字體的對話框。 它通常用于進行一些文本編輯或格式化的應用中。 ```rb #!/usr/bin/ruby ''' ZetCode Ruby GTK tutorial This example presents the Gtk::FontSelectionDialog. Author: Jan Bodnar Website: www.zetcode.com Last modified: May 2014 ''' require 'gtk3' class RubyApp < Gtk::Window def initialize super init_ui end def init_ui set_border_width 10 @label = Gtk::Label.new "The only victory over love is flight." button = Gtk::Button.new :label => "Select font" button.signal_connect "clicked" do on_clicked end fix = Gtk::Fixed.new fix.put button, 100, 30 fix.put @label, 30, 90 add fix set_title "Gtk::FontSelectionDialog" signal_connect "destroy" do Gtk.main_quit end set_default_size 300, 150 set_window_position :center show_all end def on_clicked fdia = Gtk::FontChooserDialog.new :title => "Select font name", :parent => nil response = fdia.run if response == Gtk::ResponseType::OK font_desc = Pango::FontDescription.new fdia.font_desc if font_desc @label.override_font font_desc end end fdia.destroy end end Gtk.init window = RubyApp.new Gtk.main ``` 在代碼示例中,我們有一個按鈕和一個標簽。 單擊按鈕顯示`Gtk::FontSelectionDialog`。 ```rb fdia = Gtk::FontSelectionDialog.new "Select font name" ``` 我們創建`GtkFontSelectionDialog`。 ```rb if response == Gtk::ResponseType::OK font_desc = Pango::FontDescription.new fdia.font_desc if font_desc @label.override_font font_desc end end ``` 如果單擊“確定”按鈕,則標簽小部件的字體將更改為我們在對話框中選擇的字體。 ## `Gtk::ColorSelectionDialog` `Gtk::ColorSelectionDialog`是用于選擇顏色的對話框。 ```rb #!/usr/bin/ruby ''' ZetCode Ruby GTK tutorial This example presents the Gtk::ColorSelectionDialog. Author: Jan Bodnar Website: www.zetcode.com Last modified: May 2014 ''' require 'gtk3' class RubyApp < Gtk::Window def initialize super init_ui end def init_ui set_border_width 10 @label = Gtk::Label.new "The only victory over love is flight." button = Gtk::Button.new :label => "Select colour" button.signal_connect "clicked" do on_clicked end fix = Gtk::Fixed.new fix.put button, 100, 30 fix.put @label, 30, 90 add fix set_title "Gtk::ColorSelectionDialog" signal_connect "destroy" do Gtk.main_quit end set_default_size 350, 150 set_window_position :center show_all end def on_clicked cdia = Gtk::ColorSelectionDialog.new :title => "Select colour" response = cdia.run if response == Gtk::ResponseType::OK colorsel = cdia.color_selection col = colorsel.current_rgba @label.override_color :normal, col end cdia.destroy end end Gtk.init window = RubyApp.new Gtk.main ``` 該示例與上一個示例非常相似。 這次我們更改標簽的顏色。 ```rb cdia = Gtk::ColorSelectionDialog.new :title => "Select colour" ``` 我們創建`Gtk::ColorSelectionDialog`。 ```rb if response == Gtk::ResponseType::OK colorsel = cdia.color_selection col = colorsel.current_rgba @label.override_color :normal, col end ``` 如果按“確定”按鈕,我們將獲得顏色值并修改標簽的顏色。 ![Gtk::ColorSelectionDialog](https://img.kancloud.cn/bc/d5/bcd5a04d826c1c7673cac095230e1f7b_571x304.jpg) 圖:`Gtk::ColorSelectionDialog` 在 Ruby GTK 教程的這一部分中,我們介紹了對話框。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看