import Tools from "../../../canvas/constants/tools" import { convertObjectToKeyValueString } from "../../../utils/common" import { TkinterWidgetBase } from "./base" class Button extends TkinterWidgetBase{ static widgetType = "button" constructor(props) { super(props) this.state = { ...this.state, size: { width: 80, height: 40 }, widgetName: "Button", attrs: { ...this.state.attrs, buttonLabel: { label: "Button Label", tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string toolProps: {placeholder: "Button label", maxLength: 100}, value: "Button", onChange: (value) => this.setAttrValue("buttonLabel", value) } } } } componentDidMount(){ super.componentDidMount() this.setAttrValue("styling.backgroundColor", "#E4E2E2") } generateCode(variableName, parent){ const labelText = this.getAttrValue("buttonLabel") const config = convertObjectToKeyValueString(this.getConfigCode()) return [ `${variableName} = tk.Button(master=${parent}, text="${labelText}")`, `${variableName}.config(${config})`, `${variableName}.${this.getLayoutCode()}` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, buttonLabel: this.state.attrs.buttonLabel, size: toolBarAttrs.size, ...this.state.attrs, }) } renderContent(){ return (
{/* {this.props.children} */}
{this.getAttrValue("buttonLabel")}
) } } export default Button