- Ruby Basics
- Ruby - Home
- Ruby - Overview
- Ruby - Environment Setup
- Ruby - Syntax
- Ruby - Classes and Objects
- Ruby - Variables
- Ruby - Operators
- Ruby - Comments
- Ruby - IF...ELSE
- Ruby - Loops
- Ruby - Methods
- Ruby - Blocks
- Ruby - Modules
- Ruby - Strings
- Ruby - Arrays
- Ruby - Hashes
- Ruby - Date & Time
- Ruby - Ranges
- Ruby - Iterators
- Ruby - File I/O
- Ruby - Exceptions
- Ruby Advanced
- Ruby - Object Oriented
- Ruby - Regular Expressions
- Ruby - Database Access
- Ruby - Web Applications
- Ruby - Sending Email
- Ruby - Socket Programming
- Ruby - Ruby/XML, XSLT
- Ruby - Web Services
- Ruby - Tk Guide
- Ruby - Ruby/LDAP Tutorial
- Ruby - Multithreading
- Ruby - Built-in Functions
- Ruby - Predefined Variables
- Ruby - Predefined Constants
- Ruby - Associated Tools
- Ruby Useful Resources
- Ruby - Quick Guide
- Ruby - Useful Resources
- Ruby - Discussion
- Ruby - Ruby on Rails Tutorial
Ruby/TK - Standard Dailog Box
Description
Dialog boxes are a type of window used in applications to get some information from the user, inform them that some event has occurred, confirm an action and more.
The appearance and usage of dialog boxes is usually quite specifically detailed in a platform's style guide. Tk comes with a number of dialog boxes built-in for common tasks, and which help you conform to platform specific style guidelines.
File, Directory and Color Dialog Box
Ruby/Tk provides several dialogs to let the user select files or directories. The open variant on the dialog is used when you want the user to select an existing file, while the save variant is used to choose a file to save. There are four variants, which can be used −
Tk.getOpenFile − To have one open file dialog box.
Tk.getSaveFile − To have one save file dialog box.
Tk.chooseDirectory − To have one choose directory dialog box.
Tk.chooseColor − To have one choose color dialog box.
Examples
Following example will explain how to create Open file dialog box.
require 'tk' root = TkRoot.new root.title = "Window" button_click = Proc.new { Tk.getOpenFile } button = TkButton.new(root) do text "button" pack("side" => "left", "padx"=> "50", "pady"=> "50") end button.comman = button_click Tk.mainloop
This will produce the following result −
Following example will explain how to create Choose Color dialog box.
require 'tk' root = TkRoot.new root.title = "Window" button_click = Proc.new { Tk.chooseColor } button = TkButton.new(root) do text "button" pack("side" => "left", "padx"=> "50", "pady"=> "50") end button.comman = button_click Tk.mainloop
This will produce the following result −