3 Replies - 895 Views - Last Post: 14 February 2010 - 01:40 PM Rate Topic: -----

#1 Guest_Sue816*


Reputation:

Question about Labels

Posted 07 February 2010 - 03:25 PM

Hello,

I have a question...

I am just using labels in Ruby for the first time, and I need two of them. My first one is:

enterLabel = Gtk::Label.new("Enter weight in kilos:") #label that prompts user to type into Entry box
enterText = Gtk::Entry.new 
displayLabel = Gtk::Label.new("") #label that displays the result



and I am not sure how to make a second one. Do I use "EnterLabel2", "EnterText2" and "displayLabel2"? I actually tried that, and it just didn't show up. I'm just not sure how I can add another block of code to differentiate between the first label and the second.

Thanks!
Sue

Is This A Good Question/Topic? 0

Replies To: Question about Labels

#2 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: Question about Labels

Posted 07 February 2010 - 05:06 PM

View PostSue816, on 07 February 2010 - 02:25 PM, said:

Hello,

I have a question...

I am just using labels in Ruby for the first time, and I need two of them. My first one is:

enterLabel = Gtk::Label.new("Enter weight in kilos:") #label that prompts user to type into Entry box
enterText = Gtk::Entry.new 
displayLabel = Gtk::Label.new("") #label that displays the result



and I am not sure how to make a second one. Do I use "EnterLabel2", "EnterText2" and "displayLabel2"? I actually tried that, and it just didn't show up. I'm just not sure how I can add another block of code to differentiate between the first label and the second.

Thanks!
Sue


I haven't messed much with Gtk and Ruby, but if the label's are not showing on the screen, what's the code your using to display the labels? I did a quick search for labels and found this bit of code:

fixed = GTK::Fixed.new

label1 = GTK::Label.new("Text for label 1.")
label2 = GTK::Label.new("Text for label 2.")

fixed.put label1, 20, 20
fixed.put label2, 40, 60

add fixed



Again, I haven't done much with GTK.
Was This Post Helpful? 0
  • +
  • -

#3 Xogue  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 10-February 10

Re: Question about Labels

Posted 13 February 2010 - 04:50 AM

I'm not completely sure what you are trying to achieve. From what i can tell, you are looking for the user to input the amount of kilos, and then you want to display what they typed in the second label. here is how you would accomplish that.

require 'gtk2'  #this is what lets you use the widgets from gtk
include Gtk     #this keeps you from having to put "Gtk::"  in front of Widget.new statements


window = window.new     #creates the window to show everything

enterlabel = Label.new("")     #create label 1
result = Label.new("")         #create label 2
kilos = Entry.new              #create the entry box
submit = Button.new("Submit")  #create a button (easier than watching for the enter key)

vbox = VBox.new    #used solely for organization (play with combinations of VBox and HBox)

vbox.pack_start(enterlabel)  #this puts the first label in the VBox
vbox.pack_start(kilos)       #this puts the entry box in the VBox
vbox.pack_start(submit)      #this puts the button in the VBox
vbox.pack_start(result)      #this puts the second label in the VBox

submit.signal_connect('clicked') {result.text = kilos.text}   #this tells the program to take the
                                                              #value from the entry box, and use it
                                                              #as the text for the second label, when
                                                              #the user presses the button

window.add(vbox)    #adds the VBox to the window
window.show_all     #makes the window visible
main                #run the program



this may not be what you needed, and you may have known what alot of this was. I typed the entire program for completness, and so that if someone else comes to this page, it may help them as well.

Hope I helped,

X
Was This Post Helpful? 0
  • +
  • -

#4 Sue816  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 22-April 09

Re: Question about Labels

Posted 14 February 2010 - 01:40 PM

Got it figured out, thanks very much for the replies. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1