基本上,我是以生成器格式编写代码的,但我需要在我的表屏幕上使用python代码。我不知道在kivy字符串文件中执行按钮时如何调用表格屏幕打开。以下是相同的最低工作代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
Window.size = (350,600)
class FirstWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv="""
WindowManager:
FirstWindow:
<FirstWindow>:
name: "first"
MDRoundFlatButton:
text: "SIGN UP"
font_size: 12
pos_hint: {"center_x": 0.5,"center_y": 0.3}
on_release:
app.root.current = "table" # I Want to call Table screen Here
root.manager.transition.direction = "left"
"""
class MainApp(MDApp):
def build(self):
screen = Screen()
table = MDDataTable(pos_hint={'center_x': 0.5, 'center_y': 0.5},size_hint=(0.9, 0.6),check=True,column_data=[("First Name", dp(30)),("Last Name", dp(30)),("Email Address", dp(30)),("Phone Number", dp(30))],row_data=[("John", "Elder", "zzz@xyz.com", "(123) 456-1111"),("Mary", "Elder", "yyy@xyz.com", "(123) 456-1111")])
# Bind the table
table.bind(on_check_press=self.checked)
table.bind(on_row_press=self.row_checked)
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "BlueGray"
screen.add_widget(table)
return Builder.load_string(kv) # the table screen should be called from within
# Function for check presses
def checked(self, instance_table, current_row):
print(instance_table, current_row)
# Function for row presses
def row_checked(self, instance_table, instance_row):
print(instance_table, instance_row)
MainApp().run()
关于项目的信息:我想将表链接到在线数据库。其他特性不是动态的,所以我一直在.kv文件中对它们进行编码。第一个屏幕上的按钮将引导我进入表格屏幕,但我无法对其进行编码。请帮忙
你犯了两个错误
相关问题 更多 >
编程相关推荐