所以我有一个窗口,其中有一个包含3个分区的hbox。在第二个中我有一个带有2个分区的vbox,在这个vbox中我有2个滚动窗口及其各自的树视图。
在我的代码中,我在第三个hbox分隔符中有一个Next按钮。点击之后,我销毁了2个滚动窗口,我用他的ListStore创建了一个新的Treeview,然后告诉pack_start到我有2个滚动窗口的vbox,但没有显示,只有第一个和第三个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()”的操作,则会显示蓝屏
由于
答案 0 :(得分: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()