1

I am having trouble with Python and would like to have some help.

I am making a apt GUI 'front-end' with a nice UI.

    def on_textbox_changed(self):
        self.instvar = self.installapps.get_text()

    def on_button1_clicked(self, widget):
        print "Preparing to run 'sudo apt-get install (package selected)"
        command2 = 'xterm -e sudo apt-get install ' and self.instvar
        cmd2 = commands.getoutput(command2)

Would you know how to take a textbox entry and make it a variable? I looked around the web and this is what I came up with. And every time I'm trying this it gives me this error:

Traceback (most recent call last):
  File "/home/rareshn/Documents/Zintori/Applets/aptfe/aptfe/AptfeWindow.py", line 49, in on_button1_clicked
    command2 = 'xterm -e sudo apt-get install ' and self.instvar
AttributeError: 'AptfeWindow' object has no attribute 'instvar'

If you could help me, that would be useful. Thanks!

3

You are clicking the button before self.instvar is set. The on_textbox_changed handler is probably never called. Startup Glade and select your text entry. In the property editor on the right select the signals tab and connect the GtkEditable changed signal to the correct handler.

You should also put a print statement inside on_textbox_changed to see if it really is called.

Alse, this line doesn't do what you think it does:

command2 = 'xterm -e sudo apt-get install ' and self.instvar

See this interactive session:

>>> instvar = "firefox"
>>> "xterm -e sudo apt-get install" and instvar    # Your code, wrong output
'firefox'
>>> "xterm -e sudo apt-get install %s" % instvar    # Choose one of these
'xterm -e sudo apt-get install firefox'
>>> "xterm -e sudo apt-get install " + instvar
'xterm -e sudo apt-get install firefox'
>>> "xterm -e sudo apt-get install {}".format(instvar)
'xterm -e sudo apt-get install firefox'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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