Kivy : 버튼을 클릭 할 때 라벨을 업데이트하는 방법

MagTun

버튼을 사용하여 filechooser로 선택한 일부 폴더의 경로를 검색합니다. 버튼을 클릭하면 선택한 경로를 표시하지 않도록 레이블의 텍스트를 업데이트하고 싶습니다.

내 Kv에서 :

Button:
    text:'OK'
    on_press: root.selected(filechooser.path, filechooser.selection)
Label:
    id: Lb_ListViewFolder
    text: root.Lb_ListViewFolder_text
    color: 0, 0, 0, 1
    size_hint_x: .75

.py에서 :

class MyWidget(BoxLayout):

    Lb_ListViewFolder_text = ObjectProperty("Text")
    def selected(self, a, b):
        global Lb_ListViewFolder_text
        Lb_ListViewFolder_text = b
        print(a,b)

이것은 나에게 오류를주지 않지만 레이블 텍스트는 변경되지 않습니다.

나는 또한 여기에서self.ListViewFolder.text = b 권장하는 것처럼 시도했지만 이 오류가 발생 합니다.MyWidget' object has no attribute 'Lb_ListViewFolder'

답변 을 보았지만 코드에 적용하는 데 문제가 있습니다.

나는 파이썬 3.6과 Kivy 1.9.2.dev0을 사용합니다.


경우에 따라 이것은 내 전체 코드입니다.

from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.event import EventDispatcher

from kivy.lang import Builder
root = Builder.load_string('''
<MyWidget>
    id: BL_Main
    orientation: "horizontal"
    padding: 10
    spacing: 10
    BoxLayout:
        id: BL_folder  
        orientation: "vertical"
        Button:
            id:ok
            text:'OK'
            background_color: 0,0,1,1
            height: 5
            size_hint: 0.1, 0.1
            on_press: root.selected(filechooser.path, filechooser.selection)
        BoxLayout:
            orientation:"horizontal"
            size_hint: None, 0.9
            width:150
            canvas.before:
                Color:
                    rgb: .4,.5,.5
                Rectangle: 
                    pos: self.pos
                    size: self.size

            ## multiple select folder  not possible with FileChooserListView 
            FileChooserIconView:  
                id: filechooser
                pos:self.pos
                multiselect: True
                dirselect: True

    Label:
        id: Lb_ListViewFolder
        text: root.Lb_ListViewFolder_text
        color: 0, 0, 0, 1
        size_hint_x: .75


''')

class MyWidget(BoxLayout):

    Lb_ListViewFolder_text = ObjectProperty("Text")
    def selected(self, a, b):
        global Lb_ListViewFolder_text
        Lb_ListViewFolder_text = b
        print(a,b)


class MyApp(App):
    def build(self):
        Window.clearcolor = (1, 1, 1, 1)
        return MyWidget()

MyApp().run()
El3ien

여기에서 StringProperty를 사용할 수 있습니다.

from kivy.app import App
from kivy.uix.filechooser import FileChooserListView
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import StringProperty

Builder.load_string('''

<MyLayout>:
    orientation: "vertical"
    Label:
        text: root.label_text
    Button:
        id:ok
        text:'OK'
        on_press: root.selected(filechooser.path, filechooser.selection)
    FileChooserIconView:  
        id: filechooser
        pos:self.pos
        multiselect: True
        dirselect: True

''')


class MyLayout(BoxLayout):
    label_text = StringProperty("File name")

    def selected(self, a, b):
        self.label_text = b[0]


class MyApp(App):

    def build(self):
        return MyLayout()


MyApp().run()

또는 kvlang에서 직접 변경할 수 있습니다.

<MyLayout>:
    orientation: "vertical"
    Label:
        id: dirlabel
        text: root.label_text
    Button:
        id:ok
        text:'OK'
        on_press: dirlabel.text = filechooser.selection[0]
    FileChooserIconView:  
        id: filechooser
        pos:self.pos
        multiselect: True
        dirselect: True

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Flutter : 버튼을 클릭할 때 텍스트를 업데이트하는 방법

버튼을 클릭 할 때 사라지게하는 방법

ListView의 행에서 버튼을 클릭 할 때 CursorAdapter를 사용하는 ListView를 업데이트하는 방법

"재설정"버튼을 클릭 할 때 스피너 값을 업데이트하는 방법

버튼을 클릭 할 때 모든 행 대신 한 행만 업데이트하는 방법

홈 버튼을 클릭할 때 앱을 해제하는 방법

버튼을 클릭 할 때 iframe을 표시하는 방법

kivy에서 클릭했을 때 버튼 색상을 변경하는 방법

C #에서 다른 버튼을 클릭 할 때 버튼 클릭 이벤트를 호출하는 방법

버튼을 클릭 할 때 입력 값을 얻는 방법

버튼을 클릭 할 때 PHP를 실행하는 방법?

버튼을 클릭할 때 useEffect 후크를 어떻게 업데이트합니까? (버튼 제출 방법을 작성하는 방법?)

버튼을 클릭 할 때 js에서 활성 버튼을 얻는 방법

버튼을 클릭할 때 collectionView를 새로 고치는 방법

라벨을 클릭 할 때 라디오 버튼이 확인되지 않음

버튼을 클릭 할 때 클릭 한 테이블 행의 데이터 키 값을 전달하는 방법

버튼 그룹을 클릭할 때 클릭된 버튼을 식별하는 방법

버튼을 클릭하여 kivy에서 앱의 제목을 업데이트하는 방법

recyclerview 항목을 클릭 할 때 viewModel의 라이브 데이터를 업데이트하는 방법

html에서만 버튼을 클릭 할 때 팝업 창을 닫는 방법

더하기 및 빼기 버튼을 클릭하고 해당 기능이 호출 될 때 업데이트 할 수량 값을 가져 오는 방법

버튼을 클릭 할 때 다른 레이어를 추가하는 방법

버튼을 클릭 할 때 다른 레이어를 추가하는 방법

버튼을 클릭 할 때 FAB 단축 다이얼을 열어 두는 방법

버튼을 클릭 할 때까지 입력을 비활성화하는 방법

Vue에서 버튼을 클릭 할 때 속성 값을 변경하는 방법

버튼을 클릭 할 때 BroadcastReceiver에서 새 활동을 시작하는 방법

버튼을 클릭할 때 각도 형식을 확인하는 방법

취소 버튼을 클릭 할 때 다중 삭제를 방지하는 방법

TOP 리스트

  1. 1

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  2. 2

    std :: regex의 일관성없는 동작

  3. 3

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  4. 4

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  5. 5

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  6. 6

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  7. 7

    Ionic 2 로더가 적시에 표시되지 않음

  8. 8

    Seaborn에서 축 제목 숨기기

  9. 9

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  10. 10

    복사 / 붙여 넣기 비활성화

  11. 11

    ArrayBufferLike의 typescript 정의의 깊은 의미

  12. 12

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  13. 13

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  14. 14

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  15. 15

    PRNG 기간보다 순열이 더 많은 목록을 무작위로 섞는 방법은 무엇입니까?

  16. 16

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  17. 17

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  18. 18

    잘못된 구성 개체입니다. Webpack이 Angular의 API 스키마와 일치하지 않는 구성 개체를 사용하여 초기화되었습니다.

  19. 19

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  20. 20

    R의 마침표와 숫자 사이에 문자열 삽입

  21. 21

    Assets의 BitmapFactory.decodeStream이 Android 7에서 null을 반환합니다.

뜨겁다태그

보관