我想扩展Gtk.Scale小部件(它们位于Gtk.ListBox中)并摆脱底部两个的缩进。缩进似乎与左栏中文本的长度有关。
#!/usr/bin/python3
from gi.repository import Gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
from numpy import pi
window = Gtk.Window()
window.set_default_size(800, 500)
window.connect("delete-event", Gtk.main_quit)
boxvertical = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
window.add(boxvertical)
toolbar = Gtk.Toolbar()
context = toolbar.get_style_context()
context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
boxvertical.pack_start(toolbar, False, True, 0)
horizontalbox = Gtk.Box()
boxvertical.pack_start(horizontalbox, True, True, 0)
listcontainer = Gtk.Box(spacing=5)
horizontalbox.pack_start(listcontainer, False, True, 0)
listbox = Gtk.ListBox()
listbox.set_selection_mode(Gtk.SelectionMode.NONE)
listcontainer.pack_start(listbox, False, False, 5)
def amplitude_changed(event):
print(amplitude_scale.scale.get_value())
def wavelength_changed(event):
print(wavelength_scale.scale.get_value())
row = Gtk.ListBoxRow()
listcontainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=100)
row.add(listcontainer)
label = Gtk.Label("<b>Settings</b>", xalign=0.5)
label.set_use_markup(True)
listcontainer.pack_start(label, True, True, 0)
listbox.add(row)
class ListBox():
def __init__(self, name, lower_range, upper_range):
self.name = name
self.lower_range = lower_range
self.upper_range = upper_range
# two adjustments (initial value, min value, max value,
# step increment - press cursor keys to see!,
# page increment - click around the handle to see!,
# page size - not used here)
#self.adjustment = Gtk.Adjustment(0, 0, 20,
self.row = Gtk.ListBoxRow()
self.listcontainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=100)
self.row.add(self.listcontainer)
self.label = Gtk.Label(self.name, xalign=0)
self.scale = Gtk.Scale()
self.scale.set_range(self.lower_range, self.upper_range)
#self.scale.set_hexpand(True)
self.listcontainer.pack_start(self.label, False, False, 0)
self.listcontainer.pack_start(self.scale, True, True, 0)
listbox.add(self.row)
amplitude_scale = ListBox("Amplitude", 0.0, 5.0)
amplitude_scale.scale.connect("value-changed", amplitude_changed)
wavelength_scale = ListBox("Wavelength", 0.0, 20.0)
wavelength_scale.scale.connect("value-changed", wavelength_changed)
displacement_scale = ListBox("Displacement", 0.0, 10.0)
row = Gtk.ListBoxRow()
listcontainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=100)
row.add(listcontainer)
label = Gtk.Label("Color", xalign=0)
combo = Gtk.ComboBoxText()
combo.insert(0, "0", "Red")
combo.insert(1, "1", "Green")
combo.insert(2, "2", "Blue")
listcontainer.pack_start(label, False, False, 0)
listcontainer.pack_start(combo, True, True, 0)
listbox.add(row)
fig = Figure(figsize=(10,10), dpi=80)
ax = fig.add_subplot(111)
canvas = FigureCanvas(fig)
horizontalbox.pack_start(canvas, True, True, 0)
window.show_all()
Gtk.main()
答案 0 :(得分:1)
ListBox类中的self.listcontainer应该具有以下属性:
self.listcontainer.set_property ("homogeneous", True)