我使用pandastable将CSV中的数据显示为Tkinter GUI作为表结构。该表具有垂直和水平滚动条。滚动条可以使用鼠标正常工作。当我按下向下键时,焦点转到下一行。但是,滚动条不适用于向下键。这个功能是否在Pandastable中没有实现,或者我做错了什么?
示例:
from tkinter import *
from pandastable import Table, TableModel
class TestApp(Frame):
def __init__(self, parent=None):
self.parent = parent
Frame.__init__(self)
self.main = self.master
self.main.geometry('600x400+200+100')
self.main.title('Table app')
f = Frame(self.main)
f.pack(fill=BOTH,expand=1)
df = TableModel.getSampleData()
self.table = pt = Table(f, dataframe=df, showtoolbar=True, showstatusbar=True)
pt.show()
return
app = TestApp()
#launch the app
app.mainloop()
答案 0 :(得分:1)
作为一个想法
在
../dist-packages/pandastable/core.py
在
def handle_arrow_keys(self, event):
if event.keysym == 'Up':
if self.currentrow == 0:
return
else:
#self.yview('moveto', y)
#self.rowheader.yview('moveto', y)
event.widget.config(yscrollincrement = self.rowheight)
self.rowheader.config(yscrollincrement = self.rowheight)
self.currentrow = self.currentrow -1
event.widget.yview_scroll(-1, UNITS)
self.rowheader.yview_scroll(-1, UNITS)
self.redrawVisible()
elif event.keysym == 'Down':
if self.currentrow >= self.rows-1:
return
else:
#self.yview('moveto', y)
#self.rowheader.yview('moveto', y)
event.widget.config(yscrollincrement = self.rowheight)
self.rowheader.config(yscrollincrement = self.rowheight)
self.currentrow = self.currentrow +1
event.widget.yview_scroll(1, UNITS)
self.rowheader.yview_scroll(1, UNITS)
self.redrawVisible()
只滚动一行:.config(yscrollincrement = self.rowheight)
来自
def mouse_wheel(self, event):
event.widget.yview_scroll(-1, UNITS)
self.rowheader.yview_scroll(-1, UNITS)
self.redrawVisible()