如何在GTKTreeView中创建一个空行(2个浮点数)?我设置了这个:
self.liststore = Gtk.ListStore(float, float)
self.treeview = Gtk.TreeView(model=self.liststore)
然后添加3行:
self.liststore.append([2.35, 2.40])
self.liststore.append([3.45, 4.70])
self.liststore.append()
但是当我执行程序时,第3行每个都填充0.00000。我怎样才能创建一个真正的空行?或者如何在GtkTreeView中显示空行?
我正在开发一个程序,它绘制点并在每次填充空行时添加一个新行:
#!/usr/bin/python3
from gi.repository import Gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
class DataBase():
def __init__(self):
self.window = Gtk.Window()
self.window.set_default_size(800, 500)
self.box = Gtk.Box()
self.window.add(self.box)
self.fig = Figure(figsize=(10,10), dpi=80)
self.ax = self.fig.add_subplot(111)
self.canvas = FigureCanvas(self.fig)
self.box.pack_start(self.canvas, True, True, 0)
self.liststore = Gtk.ListStore(float, float)
self.treeview = Gtk.TreeView(model=self.liststore)
self.box.pack_start(self.treeview, False, True, 0)
self.xrenderer = Gtk.CellRendererText()
self.xrenderer.set_property("editable", True)
self.column_text = Gtk.TreeViewColumn("x-Value", self.xrenderer, text=0)
self.treeview.append_column(self.column_text)
self.yrenderer = Gtk.CellRendererText()
self.yrenderer.set_property("editable", True)
self.column_editabletext = Gtk.TreeViewColumn("y-Value", self.yrenderer, text=1)
self.treeview.append_column(self.column_editabletext)
self.xrenderer.connect("edited", self.xedited)
self.yrenderer.connect("edited", self.yedited)
self.liststore.append([2.35, 2.40])
self.liststore.append([3.45, 4.70])
self.liststore.append()
def resetplot(self):
self.ax.cla()
self.ax.set_xlim(0,10)
self.ax.set_ylim(0,10)
self.ax.grid(True)
def plotpoints(self):
self.resetplot()
for row in self.liststore:
self.ax.scatter(row[:1], row[1:], marker='o', s=50)
self.fig.canvas.draw()
def xedited(self, widget, path, number):
self.liststore[path][0] = float(number.replace(',', '.'))
self.plotpoints()
def yedited(self, widget, path, number):
self.liststore[path][1] = float(number.replace(',', '.'))
self.plotpoints()
db = DataBase()
db.resetplot()
db.plotpoints()
db.window.connect("delete-event", Gtk.main_quit)
db.window.show_all()
Gtk.main()
答案 0 :(得分:1)
除非你在模型中存储字符串,否则我认为你不能,除非你有数据,否则不要添加一行。然后你可以为空行添加空字符串。