0

所以我有一个窗口,其中有一个带有 3 个分区的 hbox。在第二个中,我有一个带有 2 个分区的 vbox,在这个 vbox 内我有 2 个带有他各自树视图的滚动窗口。

在我的代码中,我在第三个 hbox 分隔符中有一个 Next 按钮。单击后,我销毁了 2 个滚动窗口,并用他的 ListStore 创建了一个新的 Treeview,并对我有 2 个滚动窗口的 vbox 说 pack_start,但没有显示,只有第一个和第三个 hbox 分隔符。

这是我的代码:(我尝试在最后一个函数中创建新的 TreeView)

import xml.etree.ElementTree as etree
import gi
from gi.repository import Gtk

present_step = 0

locale_selected = ''
keymap_selected = ''

class main():


def __init__(self):

    builder = Gtk.Builder()
    builder.add_from_file("cnchi.ui")



    self.window = builder.get_object("mainwindow")
    self.header_label = builder.get_object("label_action")
    self.progressbar = builder.get_object("progressbar1")
    self.forward_button = builder.get_object("forward_button")
    self.box = builder.get_object("box1")
    self.main_info_box = builder.get_object("box2")
    self.scrolleft = builder.get_object("scrolledwindow1")
    self.scrolright = builder.get_object("scrolledwindow2")
    self.treeview_language = builder.get_object("treeview1")
    self.treeview_keymap = builder.get_object("treeview2")



    self.window.connect("delete-event", Gtk.main_quit)
    builder.connect_signals(self)
    self.window.set_title('Cinnarch Installer')
    self.window.set_position(Gtk.WindowPosition.CENTER)


    self.set_languages_list()
    self.set_keymaps_list()


    self.window.show_all()


def set_languages_list(self):
    tree = etree.parse("locales.xml")
    root = tree.getroot()

    liststore_language = Gtk.ListStore(str)

    render = Gtk.CellRendererText()
    col_languages = Gtk.TreeViewColumn("Languages",render,text=0)
    self.treeview_language.set_model(liststore_language)
    self.treeview_language.append_column(col_languages)

    for child in root:
        liststore_language.append([child.find('language_name').text])


def set_keymaps_list(self):
    tree = etree.parse("keymaps.xml")
    root = tree.getroot()

    liststore_keymap = Gtk.ListStore(str)

    render = Gtk.CellRendererText()
    col_keymaps = Gtk.TreeViewColumn("Keymaps",render,text=0)
    self.treeview_keymap.set_model(liststore_keymap)
    self.treeview_keymap.append_column(col_keymaps)

    for child in root:
        liststore_keymap.append([child.find('language_name').text])


def on_forward_button_clicked(self, widget, data=None):
    new_value = self.progressbar.get_fraction() + 0.1
    global present_step

    if new_value > 1:
        new_value = 0

    self.progressbar.set_fraction(new_value)


    if present_step == 0:
        self.get_language_value()
        self.get_keymap_value()
        self.scrolleft.destroy()
        self.scrolright.destroy()
        # self.firstbox.destroy()
        self.timezone_window()

    elif present_step == 1:
        self.main_info_box.show()

    present_step = present_step + 1


def get_language_value(self):
    global locale_selected
    selected = self.treeview_language.get_selection()

    (ls, iter) = selected.get_selected()
    language = ls.get_value(iter,0)

    tree = etree.parse("locales.xml")
    root = tree.getroot()

    for child in root:
        if child.find('language_name').text == language:
            locale_selected = child.find('locale_name').text

def get_keymap_value(self):
    global keymap_selected
    selected = self.treeview_keymap.get_selection()

    (ls, iter) = selected.get_selected()

    keymap = ls.get_value(iter,0)

    tree = etree.parse("keymaps.xml")
    root = tree.getroot()

    for child in root:
        if child.find('language_name').text == keymap:
            keymap_selected = child.find('keymap_name').text

def timezone_window(self):
    tree = etree.parse("timezones.xml")
    root = tree.getroot()

    self.header_label.set_text("Configure your Timezone")


    liststore_timezone = Gtk.ListStore(str)

    render = Gtk.CellRendererText()
    col_timezones = Gtk.TreeViewColumn("Timezones",render,text=0)

    treeview_timezone = Gtk.TreeView(liststore_timezone)

    treeview_timezone.set_model(liststore_timezone)
    treeview_timezone.append_column(col_timezones)

    for child in root:
        liststore_timezone.append([child.find('timezone_name').text])


    self.main_info_box.pack_start(treeview_timezone,True,True,0)


if __name__ == '__main__':
    main()
    Gtk.main()

在最后一行之后,如果我执行“treeview_timezone.show()”之类的操作,则会显示蓝屏

谢谢

4

1 回答 1

1

解决了

这就是我的 timezone_window 函数现在的样子

def timezone_window(self):
    tree = etree.parse("timezones.xml")
    root = tree.getroot()

    self.header_label.set_text("Configure your Timezone")


    scrolledwindow = Gtk.ScrolledWindow()
    scrolledwindow.set_vexpand(True)


    liststore_timezone = Gtk.ListStore(str)

    render = Gtk.CellRendererText()
    col_timezones = Gtk.TreeViewColumn("Timezones",render,text=0)

    treeview_timezone = Gtk.TreeView(liststore_timezone)

    treeview_timezone.set_model(liststore_timezone)
    treeview_timezone.append_column(col_timezones)

    for child in root:
        liststore_timezone.append([child.find('timezone_name').text])

    scrolledwindow.add(treeview_timezone)
    self.main_info_box.pack_start(scrolledwindow, False, False, 0)
    treeview_timezone.show()
    scrolledwindow.show()
于 2012-07-27T14:19:58.900 回答