Reputation: 1601
I wrote the code below in PyGTK:
class Window(gtk.Window):
def __init__(self):
super(Window, self).__init__()
rbtn_one = gtk.RadioButton(label = "One")
rbtn_two = gtk.RadioButton(label = "Two", group = rbtn_one)
txt = gtk.Entry()
btn = gtk.Button("Click")
fixed = gtk.Fixed()
fixed.put(rbtn_one, 10, 10)
fixed.put(rbtn_two, 10, 40)
fixed.put(txt, 10, 70)
fixed.put(btn, 10, 100)
btn.connect("clicked", self.method)
def method(self, widget):
txt.get_text() # <-- Help here!
I'd like access to members created in the builder since method
. But I get the message: NameError: global name 'txt' is not defined
.
What am I doing wrong? What is the best place to define the variables? Should I use properties?
Upvotes: 0
Views: 135
Reputation: 7545
If you want txt to be available anywhere in the instance, the easiest way is to assign it to self:
self.txt = gtk.Entry()
...
self.txt.get_text()
Upvotes: 3