我有一个非常简单的PyGTK应用程序,它包含1个小部件 - 一个ComboBox。出于某种原因,当我运行我的python脚本时,ComboBox不可见。主窗口可见而不是ComboBox。注意我已成功确定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()
答案 0 :(得分:1)
您忘记了show()
您的组合框。 (在窗口上show_all()
通常更容易。)