=begin
https://www.tutorialspoint.com/ruby/ruby_tk_guide.htm
=end
require 'tk'
$mili = TkVariable.new
$pulgadas = TkVariable.new
$cen = TkVariable.new
$metro = TkVariable.new
$nombre = TkVariable.new
v = TkRoot.new {title "Conversor"}
v.geometry('640x480')
v.minsize(600,380)
TkLabel.new(v) {
text ' ¿Cómo te llamas ? '
font TkFont.new('times 15')
place('relx'=>0.1,'rely'=>0.150)
}
e5 = TkEntry.new(v){
textvariable $nombre
font TkFont.new('times 15')
place('relx'=>0.55,'rely'=>0.15)
borderwidth 2
}
e1 = TkLabel.new(v) {
text 'Conversión de pulgadas a milÃmetros'
font TkFont.new('times 20 bold')
foreground "red"
place('relx'=>0.1,'rely'=>0.05)
}
e2 = TkLabel.new(v) {
text 'Escribe la cantidad de pulgadas: '
font TkFont.new('times 15')
foreground "blue"
place('relx'=>0.1,'rely'=>0.25)
}
e3 = TkEntry.new(v){
textvariable $pulgadas
font TkFont.new('times 15')
place('relx'=>0.55,'rely'=>0.25)
borderwidth 2
}
TkLabel.new(v) {
text ' Equivale a: '
font TkFont.new('times 15')
place('relx'=>0.33,'rely'=>0.50)
}
TkLabel.new(v) {
textvariable $mili
foreground "red"
font TkFont.new('times 20')
place('relx'=>0.50,'rely'=>0.49)
}
TkLabel.new(v) {
textvariable $cen
foreground "red"
font TkFont.new('times 20')
place('relx'=>0.50,'rely'=>0.59)
}
TkLabel.new(v) {
textvariable $metro
foreground "red"
font TkFont.new('times 20')
place('relx'=>0.50,'rely'=>0.69)
}
TkButton.new(v) {
text 'Calcular'
command {cal}
place('relx'=>0.6,'rely'=>0.38)
}
e4 = TkLabel.new(v) {
text 'Una pulgada equivale a 25.4 milÃmetros. '
font TkFont.new('times 15')
place('relx'=>0.3,'rely'=>0.8)
}
=begin
TkLabel.new(v) {
textvariable $nombre
font TkFont.new('times 16')
foreground "blue"
place('relx'=>0.08,'rely'=>0.73)
}
=end
TkLabel.new(v) {
text " milÃmetros."
font TkFont.new('times 15')
place('relx'=>0.70,'rely'=>0.50)
}
TkLabel.new(v) {
text " centÃmetros."
font TkFont.new('times 15')
place('relx'=>0.70,'rely'=>0.60)
}
TkLabel.new(v) {
text " metros."
font TkFont.new('times 15')
place('relx'=>0.70,'rely'=>0.70)
}
salir = TkButton.new(v) {
text 'Salir'
command 'exit'
place('relx'=>0.9,'rely'=>0.9)
}
$foto = TkPhotoImage.new
$foto.file = "buena1.gif"
# con el método .round redondeamos el número para que muestre dos decimales
def cal
begin
$mili.value = (25.4*$pulgadas).round(2)
$cen.value = (2.54*$pulgadas).round(2)
$metro.value = (0.254*$pulgadas).round(2)
rescue
$mili.value = ''
$cen.value = ''
$metro.value = ''
end
TkLabel.new { #Unas etiqueta con sorpresa
text 'Gracias'
font TkFont.new('times 16')
foreground "blue"
place('relx'=>0.09,'rely'=>0.83)
TkLabel.new {
textvariable $nombre
font TkFont.new('times 16')
foreground "blue"
place('relx'=>0.08,'rely'=>0.73)
}
label = TkLabel.new
label.image = $foto
label.place('x' => 80, 'y' => 250)
}
end
Tk.mainloop
Ruby es un lenguaje es un universo, donde todo parte de un mismo objeto "main" y desde ahí se diferencian los demás. Es realmente fácil de ir comprendiendo y nos va a permitir ir plasmando la idea que generó la necesidad de hacer ese programa pero muy humanamente.
6 nov 2018
Teoría - TK8
ejercicio TK -1
#!/usr/bin/ruby #https://sandbox.mc.edu/~bennet/ruby/code/tk2_rb.html # Import the library. require 'tk' # Root window. root = TkRo...
-
#!/usr/bin/ruby #https://sandbox.mc.edu/~bennet/ruby/code/tk2_rb.html # Import the library. require 'tk' # Root window. root = TkRo...
-
Primero has de tener instalado Ruby Después, instala la gema ocra así: gem install ocra Como da problemas si tan sólo llamamos a la gema oc...
-
https://sourceforge.net/projects/redsky-ruby/files/RedSky%20Stable%20Setup/RedSky%20Ruby%20v2019.1%20SETUP.exe/download