Label Change on Button Click

More
10 years 7 months ago #72072 by squan09
I am just getting started with GladeVCP and am trying to make a button that will change a label in axis. Here is my code so far:
Code:
#!/usr/bin/env python import gtk import hal_glib import hal class HandlerClass: def on_button1_clicked(self, button, data=None): self.label1.set_text("clicked") print("clicked") def __init__(self, halcomp,builder,useropts): self.builder = gtk.Builder() self.halcomp = halcomp self.builder.add_from_file('button.glade') self.builder.connect_signals(self) self.label1 = self.builder.get_object('label1') self.window = self.builder.get_object('window1') def get_handlers(halcomp,builder,useropts): return [HandlerClass(halcomp,builder,useropts)]

When I run this I "clicked" is printed to the terminal, but the label does not change. If I add self.window.show() to the init then the window will show the button and label and the label will change there. Any idea why it would change the one label and not the other in Axis?

Please Log in to join the conversation.

More
10 years 7 months ago #72076 by cmorley
You need a reference to the object before you can manipulate it.
try adding :
self.label1 = self.builder..get_object( "label1" )

to the __init__ function

I assume the label you wish to modify is called label1 in glade.

Chris M

Please Log in to join the conversation.

More
10 years 7 months ago #72078 by squan09
Thanks, but I already have that on the second line from the bottom of the init function. Also, the label does change, but only when opened in a separate window outside of the the Axis GUI.

Please Log in to join the conversation.

More
10 years 7 months ago #72123 by cmorley
sorry i didn't scroll the code...
This code is not useful...
self.window = self.builder.get_object('window1')
window1 gets replaced when the panel is re-parented into axis.
I can't see how that would affect the window based on the code you have shown.
Can you post the glade file too.

Chris M

Please Log in to join the conversation.

More
10 years 7 months ago #72269 by squan09
So here is the glade file. I removed self.window = self.builder.get_object('window1') and had the same results.

Could this have anything to do with calling self.builder = gtk.Builder(), rather than self.builder = builder. From looking at others code that is only difference I can find. If I do change it to self.builder = builder though, the button inside of the Axis GUI does not function. Can you explain or do you know of a reference that explains the difference between gtk.Builder() and builder.

Attachment not found

Please Log in to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum