我有一个状态栏,但我如何使它工作?

时间:2011-05-08 18:04:42

标签: python pygtk connect statusbar

此代码显示状态栏。但是,当我点击一个按钮时,它并没有说我在状态栏中已经这样做了。

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()

2 个答案:

答案 0 :(得分:1)

您需要通过向其发送消息来显式更新状态栏。文档有a brief example showing how the statusbar works

试试此部分,如果消息显示,请告诉我:

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"])

答案 1 :(得分:1)

这个怎么样?

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"])