GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 22, 2014 1:58 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Simple program that sums two numbers.
PostPosted: Sat Oct 19, 2013 2:02 am 
Offline

Joined: Fri Oct 18, 2013 8:09 pm
Posts: 1
Well guys, i'm pretty new to gtk and glade.

I was watching a tutorial and making a simple project, but i got an error while trying to set_text to a Text Entry on glade.

Here goes my code:

Code:
import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import gtk.glade
except:
    print "GTK not available"
    sys.exit(1)



class adder(object):

    result = 0

    def __init__(self, number1, number2):
        self.result = int(number1) + int(number2)

    def give_result(self):
        return str(self.result)



class interface(object):

    gladefile = None

    def __init__(self):
        self.gladefile = "main.glade"
        self.glade = gtk.Builder()
        self.glade.add_from_file(self.gladefile)
        self.glade.connect_signals(self)
        self.glade.get_object("main_window").show_all()
        self.glade.get_object("warning_hbox").hide()

        gtk.main()

    def on_main_window_destroy(self, widget):
        sys.exit(0)

    def on_exit_button_clicked(self, widget):
        sys.exit(0)

    def on_sum_button_clicked(self, widget):
        try:
            operation = adder(self.glade.get_object("entry_first_number").get_text(), self.glade.get_object("entry_second_number").get_text())
        except ValueError:
            self.glade.get_object("warning_hbox").show()
            self.glade.get_object("entry_result").set_text("ERROR") #Error: "NoneType" object has no attribute "set_text"

        self.glade.get_object("warning_hbox").hide()
        self.glade.get_object("entry_result").set_text(operation.give_result()) #Error: "NoneType" object has no attribute "set_text"



main = interface()


This is the part where the error appears:

Code:
    def on_sum_button_clicked(self, widget):
        try:
            operation = adder(self.glade.get_object("entry_first_number").get_text(), self.glade.get_object("entry_second_number").get_text())
        except ValueError:
            self.glade.get_object("warning_hbox").show()
            self.glade.get_object("entry_result").set_text("ERROR") #Error: "NoneType" object has no attribute "set_text"

        self.glade.get_object("warning_hbox").hide()
        self.glade.get_object("entry_result").set_text(operation.give_result()) #Error: "NoneType" object has no attribute "set_text"


I have already changed the Text Entry for a label (and it worked), but the tutorial i was watching made it with the Text Entry. So, does anyone knows how can I set a text to a Text Entry?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group