trame-vuetify
Trame-vuetify extends Trame's widgets and UI with Vuetify's Material Design components. Vuetify is a UI Library with beautifully handcrafted Material Components, enabling users to create rich web applications without extensive design skills. It is not meant to be used standalone but as a dependency of `trame`. The current version is 3.2.1, and it follows the release cadence of `trame` and `Vuetify` updates.
Warnings
- breaking Trame v3 (released January 2024) defaults to a Vue 3 client. Older Trame applications built with `trame` v2 (which used Vue 2 by default) may experience breaking changes, especially if not explicitly setting `server.client_type = "vue2"` or if relying on Vuetify 2 specific APIs. `trame-vuetify` must now be explicitly installed as it's no longer bundled with the `trame` core.
- gotcha Vuetify component names in HTML (kebab-case, e.g., `<v-text-field>`) translate to Python as CamelCase class names (e.g., `vuetify.VTextField`).
- gotcha Implicit boolean attributes in Vuetify HTML (e.g., `<v-text-field disabled />`) must be explicitly set to `True` in Python (e.g., `vuetify.VTextField(disabled=True)`).
- gotcha HTML attributes using dashes (`-`) or colons (`:`) in Vuetify (e.g., `v-model`, `:suffix`) are converted to underscores (`_`) in Python (e.g., `v_model`, `suffix`).
- gotcha Vue.js events prefixed with `@` (e.g., `@click="runMethod"`) are handled by passing the Python function reference directly to the attribute name (e.g., `click=runMethod`). For direct JS expressions, wrap them in a string.
Install
-
pip install trame-vuetify
Imports
- vuetify
from trame.widgets import vuetify
Quickstart
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify
server = get_server(client_type="vue3") # Set client_type explicitly for Trame v3
@server.state.change("slider_value")
def on_slider_change(slider_value, **kwargs):
print(f"Slider value changed to: {slider_value}")
with SinglePageLayout(server) as layout:
layout.title.set_text("Trame-Vuetify Example")
with layout.content:
with vuetify.VContainer():
vuetify.VSlider(
label="Example Slider",
min=0,
max=100,
v_model=("slider_value", 50), # (state_variable, default_value)
class_="my-4",
)
vuetify.VTextField(
label="Your Name",
v_model=("name", "Trame User"),
clearable=True,
outlined=True,
)
vuetify.VBtn(
"Hello",
click="alert(`Hello ${name}!`)",
color="primary",
class_="mt-2",
)
if __name__ == "__main__":
server.start()