How would I go about changing the constraints of a view? In the example code below I’m trying to redefine the constraints of slide_view when the menu button button is pressed, which (obviously) doesn’t work.
import ui
from anchor import *
if __name__ == '__main__':
class Test_slide(ui.View):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.previous_size_class = None
self.active_constraints = []
enable(self)
self.create_ui()
def style(self, view):
view.background_color = 'white'
view.border_color = 'black'
view.border_width = 1
view.text_color = 'black'
view.tint_color = 'black'
def create_ui(self):
slide_frame = View(name='Slide frame')
slide_frame.show = True
self.style(slide_frame)
self.add_subview(slide_frame)
slide_frame.dock.leading(share=.3)
main_frame = View(name='Main frame')
self.style(main_frame)
self.add_subview(main_frame)
main_frame.dock.fit()
main_frame.dock.trailing()
main_frame.at.leading == slide_frame.at.trailing
def slide(sender):
slide_frame.show = not slide_frame.show
if slide_frame.show:
print('slide in')
slide_frame.dock.leading(share = .3)
else:
print('slide out')
slide_frame.dock.leading(share=.0)
menu_button = Button(name = 'menu button', title = 'Menu').dock.fit()
self.style(menu_button)
menu_button.action = slide
main_frame.add_subview(menu_button)
menu_button.dock.top_leading()
root = Test_slide()
root.present('fullscreen', hide_title_bar=True, animated=False)
The code is just an edited version of the example script in the anchor module by @mikael