Hello
I have made a simple gui tic tac toe game using glade and python 2.6/
Now I want to change the text of the button when i click it.
Does anyone know how to do this??

code:

#!/usr/bin/env python

import gtk
import gtk.glade
import sys

class iksoks:

    wTree = None

    def __init__(self):
        self.wTree = gtk.glade.XML("ttt.glade")

        rc = {
            "on_button1_clicked" : self.b1,
            "on_button2_clicked" : self.b2,
            "on_button3_clicked" : self.b3,
            "on_button4_clicked" : self.b4,
            "on_button5_clicked" : self.b5,
            "on_button6_clicked" : self.b6,
            "on_button7_clicked" : self.b7,
            "on_button8_clicked" : self.b8,
            "on_button9_clicked" : self.b9,
            }
        self.wTree.signal_autoconnect(rc)
        self.wnd = self.wTree.get_widget("window1")


        global r
        global a1
        global a2
        global a3
        global b1
        global b2
        global b3
        global c1
        global c2
        global c3

        r = 1

    def b1(self, widget):
        if r == 1:
            self.wTree.get_widget("button1").set_label("x")
            a1 = "x"
            r = 2
        else:
            self.wTree.get_widget("button1").set_label("o")
            a1 = "o"
            r = 1

    def b2(self, widget):
        if r == 1:
            self.wTree.get_widget("button2").set_label("x")
            a2 = "x"
            r = 2
        else:
            self.wTree.get_widget("button2").set_label("o")
            a2 = "o"
            r = 1

    def b3(self, widget):
        if r == 1:
            self.wTree.get_widget("button3").set_label("x")
            a3 = "x"
            r = 2
        else:
            self.wTree.get_widget("button3").set_label("o")
            a3 = "o"
            r = 1

    def b4(self, widget):
        if r == 1:
            self.wTree.get_widget("button4").set_label("x")
            b1 = "x"
            r = 2
        else:
            self.wTree.get_widget("button4").set_label("o")
            b1 = "o"
            r = 1

    def b5(self, widget):
        if r == 1:
            self.wTree.get_widget("button5").set_label("x")
            b2 = "x"
            r = 2
        else:
            self.wTree.get_widget("button5").set_label("o")
            b2 = "o"
            r = 1

    def b6(self, widget):
        if r == 1:
            self.wTree.get_widget("button6").set_label("x")
            b3 = "x"
            r = 2
        else:
            self.wTree.get_widget("button6").set_label("o")
            b3 = "o"
            r = 1

    def b7(self, widget):
        if r == 1:
            self.wTree.get_widget("button7").set_label("x")
            c1 = "x"
            r = 2
        else:
            self.wTree.get_widget("button7").set_label("o")
            c1 = "o"
            r = 1

    def b8(self, widget):
        if r == 1:
            self.wTree.get_widget("button8").set_label("x")
            c2 = "x"
            r = 2
        else:
            self.wTree.get_widget("button8").set_label("o")
            c2 = "o"
            r = 1

    def b9(self, widget):
        if r == 1:
            self.wTree.get_widget("button9").set_label("x")
            c3 = "x"
            r = 2
        else:
            self.wTree.get_widget("button9").set_label("o")
            c3 = "o"
            r = 1

    
        


io = iksoks()
io.wnd.show()
gtk.main()

Use:

button.SetLabel("label")

It doiesent work

Why do you have so many global statements?
Or did glade do that?
You should have self.r, self.a1, etc
instead of them all being global.
Global is bad.

In the time i wrote this code i didnt knew for self. Now I have a new code but my problem is when i click one button that the text of the button changes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.