Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to call function in quickly?

Here is my code:

def finish_initializing(self, builder): # pylint: disable=E1002
    super(projectWindow, self).finish_initializing(builder)
    self.AboutDialog = AboutprojectDialog
    self.PreferencesDialog = PreferencesprojectDialog
def test(self,widget):
    print "clicked"
def on_myButton_clicked(self,widget):
    test()

The following error I get: NameError: global name 'test' is not defined

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

According to the tutorial video on http://developer.ubuntu.com/get-started/ ,

If your widget is named "myButton",

def test(self,widget):
    print "clicked"
def on_myButton_clicked(self,widget):
    test()

This part of your code should be rewritten to below:

self.myButton = self.builder.get_object("myButton") 
def test(widget):
    print "clicked"
def on_myButton_clicked(self, widget):
    self.test()

In advance, it is necessary to start Glade by quickly design command, and to create the button widget.

share|improve this answer
add comment

test is a method of the class you are writing so you have to use

$self.test(some_widget)

where some_widget is whatever value you want to use for the widget parameter of test.

By the way quickly isn't a programming language but a tool. The programming language you are using is Python.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.