from kivy.metrics import dp
from kivy.clock import Clock
from kivymd.app import MDApp
from kivymd.uix.datatables import MDDataTable
from kivy.lang import Builder
from kivy.core.window import Window
Window.size = (1920, 1080)
KV = '''
FloatLayout:
MDRaisedButton:
text: "Strategies Using Date Only"
pos_hint: {'center_x': .5, 'center_y': .10}
on_release : app.create_table()
elevation: 12
MDCard:
id: card
size_hint: None, None
size: "1000dp", "1000dp"
pos_hint: {"center_x": .5, "center_y": .8}
ripple_behavior: True
elevation: 12
'''
class Example(MDApp):
r_data = [('3100','20.5')]
c_data = [('Strike Price',dp(30)),('Price',dp(30))]
i = 0
def build(self):
return Builder.load_string(KV)
def on_start(self):
Clock.schedule_interval(self.update_table,0.5)
def on_row_press(self, instance_table, instance_row):
'''Called when a table row is clicked.'''
print(instance_table, instance_row)
def on_check_press(self, instance_table, current_row):
'''Called when the check box in the table row is checked.'''
print(instance_table, current_row)
def create_table(self):
self.data_tables = MDDataTable(
id = 'table',
size_hint=(0.9, 0.6),
use_pagination=True,
check=True,
column_data=self.c_data,
row_data=self.r_data,
)
self.data_tables.bind(on_row_press=self.on_row_press)
self.data_tables.bind(on_check_press=self.on_check_press)
self.root.ids.card.add_widget(self.data_tables)
def update_table(self, *args):
self.r_data = [(str(3100+self.i),str(20.5+self.i))]
self.i += 1
try:
self.root.ids.card.clear_widgets()
self.create_table()
except:
pass
Example().run()
我正在使用此代码来更改数据表的行值。但是,我无法选中该行。还有另一种方法可以做到这一点吗?基本上,我正在尝试为数据制作数据表hft
,并且我想在运行时修改数据表。这是一个屏幕截图:
有人可以帮我吗?提前致谢!