내 응용 프로그램에서는 사용자에게 일반적인 스프레드 시트/테이블 (OO.O/Excel 스타일)을 제시 한 다음 값을 가져 와서 내부적으로 처리하려고합니다.스프레드 시트/테이블을 PyGTK 애플리케이션에 삽입 하시겠습니까?
PyGTK 용 기존 위젯이 있습니까? PyGTK FAQ에는 GtkGrid이 언급되어 있지만 링크가 죽었으므로 어디서나 타르볼을 찾을 수 없습니다.
내 응용 프로그램에서는 사용자에게 일반적인 스프레드 시트/테이블 (OO.O/Excel 스타일)을 제시 한 다음 값을 가져 와서 내부적으로 처리하려고합니다.스프레드 시트/테이블을 PyGTK 애플리케이션에 삽입 하시겠습니까?
PyGTK 용 기존 위젯이 있습니까? PyGTK FAQ에는 GtkGrid이 언급되어 있지만 링크가 죽었으므로 어디서나 타르볼을 찾을 수 없습니다.
예를 들어 .Net의 GridView보다 약간 더 수동 일 수도 있지만 Tree View 위젯은 필요한 것 이상을 수행 할 것입니다. PyGtk TreeView
당신은 웹 페이지 뷰어를 내장 고려해 볼 수 있습니다 참조하십시오 - 당신이 그와 함께 많은 작업을 수행 할 수 있습니다 http://blog.mypapit.net/2009/09/pymoembed-web-browser-in-python-gtk-application.html
GtkGrid
는 찬성되지 않습니다의 더 강력하고 GtkTreeView
더 사용자 정의 할 수 있습니다.
나무와 목록을 표시 할 수 있습니다. 테이블과 같이 작동 시키려면 데이터를 가져올 ListStore
을 정의하고 표시 할 각 열에 대해 TreeViewColumn
을 정의하고 열 표시 방법을 정의하려면 CellRenderer
을 정의해야합니다. 이렇게 데이터와 렌더링을 분리하면 텍스트 상자 나 이미지와 같이 셀에 다른 컨트롤을 렌더링 할 수 있습니다.
GtkTreeView
은 매우 유연하지만 많은 옵션 때문에 처음에는 복잡해 보입니다. 이를 돕기 위해 PyGTK tutorial에는 relevant section이 있습니다 (이 섹션뿐만 아니라 전체적으로 읽어야 함).
, 여기에 예제 코드와 내 시스템에서 실행 그것의 스크린 샷이다 :, @nosklo 대답에 대한
이
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
class TreeViewColumnExample(object):
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("TreeViewColumn Example")
self.window.connect("delete_event", self.delete_event)
# create a liststore with one string column to use as the model
self.liststore = gtk.ListStore(str, str, str, 'gboolean')
# create the TreeView using liststore
self.treeview = gtk.TreeView(self.liststore)
# create the TreeViewColumns to display the data
self.tvcolumn = gtk.TreeViewColumn('Pixbuf and Text')
self.tvcolumn1 = gtk.TreeViewColumn('Text Only')
# add a row with text and a stock item - color strings for
# the background
self.liststore.append(['Open', gtk.STOCK_OPEN, 'Open a File', True])
self.liststore.append(['New', gtk.STOCK_NEW, 'New File', True])
self.liststore.append(['Print', gtk.STOCK_PRINT, 'Print File', False])
# add columns to treeview
self.treeview.append_column(self.tvcolumn)
self.treeview.append_column(self.tvcolumn1)
# create a CellRenderers to render the data
self.cellpb = gtk.CellRendererPixbuf()
self.cell = gtk.CellRendererText()
self.cell1 = gtk.CellRendererText()
# set background color property
self.cellpb.set_property('cell-background', 'yellow')
self.cell.set_property('cell-background', 'cyan')
self.cell1.set_property('cell-background', 'pink')
# add the cells to the columns - 2 in the first
self.tvcolumn.pack_start(self.cellpb, False)
self.tvcolumn.pack_start(self.cell, True)
self.tvcolumn1.pack_start(self.cell1, True)
self.tvcolumn.set_attributes(self.cellpb, stock_id=1)
self.tvcolumn.set_attributes(self.cell, text=0)
self.tvcolumn1.set_attributes(self.cell1, text=2,
cell_background_set=3)
# make treeview searchable
self.treeview.set_search_column(0)
# Allow sorting on the column
self.tvcolumn.set_sort_column_id(0)
# Allow drag and drop reordering of rows
self.treeview.set_reorderable(True)
self.window.add(self.treeview)
self.window.show_all()
def main():
gtk.main()
if __name__ == "__main__":
tvcexample = TreeViewColumnExample()
main()
감사합니다 - 불행하게도, 원래 이미지가 죽은; 그래서 나는 귀하의 게시물을 편집하고 내 시스템에서 스크린 샷을 추가했습니다. 건배! – sdaau