我有一个状态栏,但如何让它发挥作用?

发布于 2024-11-05 23:09:07 字数 2000 浏览 0 评论 0原文

这段代码显示了一个状态栏。但是,当我单击按钮时,状态栏中并没有显示我已这样做。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2024-11-12 23:09:07

您需要通过向状态栏推送消息来显式更新状态栏。该文档有一个简短的示例,展示了状态栏的工作原理

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

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

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"])
你的心境我的脸 2024-11-12 23:09:07

这又如何呢?

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

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"])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文