【问题标题】:PyGTK ComboBox Not VisiblePyGTK 组合框不可见
【发布时间】:2014-03-31 00:56:42
【问题描述】:

我有一个非常简单的 PyGTK 应用程序,其中包含 1 个小部件 - 一个 ComboBox。由于某种原因,当我运行我的 python 脚本时,组合框是不可见的。主窗口可见,但组合框不可见。请注意,我已成功确定 ComboBox 存在并将其添加到主窗口(将小部件添加到框,然后将其添加到主窗口)。

如何让我的 ComboBox 出现?

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


class MainApp:

    def __init__(self):
        self.encryptFile = True
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        main_box   = gtk.VBox(True, 10)

        client_store     = gtk.ListStore(str)
        self.clientFiles = ("a","b","c")

        for f in self.clientFiles:
            client_store.append([f])

        combobox        = gtk.ComboBox(client_store)
        renderer_text   = gtk.CellRendererText()
        combobox.pack_start(renderer_text, True)
        combobox.add_attribute(renderer_text, "text", 0)
        combobox.set_size_request(200,25)

        main_box.pack_start(combobox)
        main_box.show()

        self.window.add(main_box)
        self.window.show()

    def main(self):
        gtk.main()

    def delete_event(self, widget, event, data=None):
        return False

    def destroy(self, widget, data=None):
        gtk.main_quit()

if __name__ == "__main__":
    app = MainApp()
    app.main()

【问题讨论】:

    标签: python gtk pygtk


    【解决方案1】:

    您忘记show() 您的组合框。 (在窗口上做show_all() 通常更容易。)

    【讨论】:

    • 谢谢 :D 非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多