메뉴

2017-11-02 1 views
0

menu.py 메뉴를 설정하는 방법

set menu in left side메뉴

from kivy.app import App 
from kivy.lang import Builder 

kv_str = Builder.load_string(''' 
ActionBar: 
    pos_hint: {'top':1} 
    ActionView: 
     use_separator: True 
     ActionPrevious: 
      title: 'Example App' 
      with_previous: False 
     ActionButton: 
      text: 'File' 
     ActionButton: 
      text: 'Edit' 
     ActionGroup: 
      text: 'Tools' 
      mode: 'spinner' 
      ActionButton: 
       text: 'Tool1' 
      ActionButton: 
       text: 'Tool2' 
      ActionButton: 
       text: 'Tool3' 
      ActionButton: 
       text: 'Tool4' 
''') 


class ExampleApp(App): 
    def build(self): 
     return kv_str 

if __name__ =='__main__': 
    ExampleApp().run() 
대신 예를 들어 app.After의 왼쪽에 설정 오른쪽 side.How 오는 side.Now이 메뉴를 왼쪽 그 메뉴 아래에 작은 아이콘 추가 (두 번째 행)를 추가하십시오.

첫 번째 행 - (하위 메뉴) 파일 편집 도구
둘째 행 - icon1 icon2 icon3

+1

Kivy 드롭 다운 목록을 사용하여 메뉴를 만들 수 있습니다. https://stackoverflow.com/questions/46312856/creating-a-main-menu-for-a-mobile-app-in-python에서 내 게시물을 참조하십시오. – ikolim

+0

안녕하세요, 저를 도와 주셔서 감사합니다. – Yash

답변

1

나는 적어도 광범위을 변경하지 않고 액션 바의 측면을 전환 할 수 있다고 생각하지 않습니다. 그러므로 여기에 왼쪽에 버튼이있는 솔루션이 있습니다. 그것은 아름답 지 않습니다. 혼자서도 사이징 및 배경색을 멋지게 만들 필요가 있습니다.

from kivy.app import App 
from kivy.uix.button import Button 
from kivy.uix.dropdown import DropDown 
from kivy.uix.boxlayout import BoxLayout 
from kivy.lang import Builder 


class CustDrop(DropDown): 
    def __init__(self, **kwargs): 
     super(CustDrop, self).__init__(**kwargs) 
     self.select('') 


kv_str = Builder.load_string(''' 


BoxLayout: 
    orientation: 'vertical' 
    BoxLayout: 
     canvas.before: 
      Rectangle: 
       pos: self.pos 
       size: self.size 
      Color: 
       rgb: (1,1,1) 
     size_hint_y:1 
     Button: 
      text: 'File' 
     Button: 
      text: 'Edit' 


     Button: 
      id: btn 
      text: 'Tools' 
      on_release: dropdown.open(self) 
      #size_hint_y: None 
      #height: '48dp' 


     CustDrop: 

      id: dropdown 

      Button: 
       text: 'First Item' 
       size_hint_y: None 
       height: '48dp' 
       on_release: dropdown.select('') 
       on_release: print('First Item pressed') 

      Button: 
       text: 'First Item' 
       size_hint_y: None 
       height: '48dp' 
       on_release: dropdown.select('') 


      Button: 
       text: 'Third Item' 
       size_hint_y: None 
       height: '48dp' 
       on_release: dropdown.select('') 

     Label: 
      size_hint_x: 4 

    Label: 
     size_hint_y: 9 

''') 


class ExampleApp(App): 
    def build(self): 
     return kv_str 

if __name__ =='__main__': 
    ExampleApp().run() 

enter image description here

나는 선택 방법에 빈 문자열을 전달하여 다소 속였 어. 아마, DropDown은 원래 그런 식으로 사용하기위한 것이 아닙니다.