开发者

I have a status bar but how do I make it work?

开发者 https://www.devze.com 2023-03-03 14:51 出处:网络
This code shows me a status bar. However when I click a button it does not say that I have done so in the status bar.

This code shows me a status bar. However when I click a button it does not say that I have done so in the status bar.

import pygtk
pygtk.require('2.0')
import gtk

import subprocess

class Example:
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_size_request(400, 500)
        window.set_title("GTK Menu")
        window.connect("delete_event",
                       lambda w,e: gtk.main_quit())

        vbox = gtk.VBox(False, 0)
        window.add(vbox)
        vbox.show()
开发者_开发技巧
        button = gtk.Button("Write")
        button.connect("clicked", self.clicked_Write)
        vbox.pack_end(button, True, True, 2)
        button.show()

        button2 = gtk.Button("Draw")
        button2.connect("clicked", self.clicked_Scrible)
        vbox.pack_end(button2, True, True, 2)
        button2.show()

        button3 = gtk.Button("Final Test")
        button3.connect("clicked", self.clicked_Final)
        vbox.pack_end(button3, True, True, 2)
        button3.show()

        button4 = gtk.Button("Helloworld")
        button4.connect("clicked", self.clicked_Hello)
        vbox.pack_end(button4, True, True, 2)
        button4.show()

        button5 = gtk.Button("Facebook")
        button5.connect("clicked", self.clicked_Facebook)
        vbox.pack_end(button5, True, True, 2)
        button5.show()

        # Add status bar to vbox
        self.statusbar = gtk.Statusbar()
        vbox.pack_start(self.statusbar, False, False, 0)



        window.show_all()


    def clicked_Write(self, widget):
        subprocess.Popen(["python", "Helloworld.py"])

    def clicked_Scrible(self, widget):
        subprocess.Popen(["python", "scrible.py"])

    def clicked_Final(self, widget):
        subprocess.Popen(["python", "Final.py"])

    def clicked_Hello(self, widget):
        subprocess.Popen(["python", "Helloword.py"])

    def clicked_Facebook(self, widget):
        subprocess.Popen(["python", "facebookfinal.py"])


    def main(self):
        gtk.main()
        return 0

Example().main()


You need to explicitly update the statusbar by pushing a message to it. The documentation has a brief example showing how the statusbar works:

Try this part, and let me know if the message shows:

def clickedWrite(self, widget):
    # push a new message to the statusbar, using context_id 0
    self.statusbar.push(0, "called Write")
    subprocess.Popen(["python", "Helloworld.py"])


What about this?

def clickedWrite(self, widget):
    # push a new message to the statusbar, using context_id 0
    self.statusbar.push(0, "called Write")
    while gtk.events_pending():
       gtk.main_iteration_do(False)
    subprocess.Popen(["python", "Helloworld.py"])
0

精彩评论

暂无评论...
验证码 换一张
取 消