Kivy popup penceresi

Sorunu buldum ve cozdum:

Hataların:

  • main.kv dosyası Builder.load_file metodu ile yuklenmemis
  • main.kv dosyasında yazman gerekirken <popup_cls> yazmıssın.Program hata vermez ama istedigini de gostermez.

Aslında daha once de soyleyecektim ama kv dosyasını yeniden duzenlemem lazımdı hata veriyordu,tahtada onu duzelttim.Ondan cevap biraz gec oldu.

ornek:

from kivy.app import App 
from kivy.uix.boxlayout import BoxLayout 
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup 
from kivy.core.window import Window
from kivy.lang import Builder


kv = """
<popupcls>:
    size_hint: .2,.3
    auto_dismiss: False
    title: "Uyarı"
    Button:
        text: "Close"
        on_press: root.dismiss()
        
<main2>: 
    orientation: "vertical"
    padding: 10
    spacing: 10

    BoxLayout:
        orientation: "horizontal"
        size_hint_x: .22

        Label:
            text: "Are You Over 18"
            #size_hint_x: .80

	CheckBox:
	    on_active: root.checkbox_18_clicked(self, self.active)
	    size_hint_x: .60

    BoxLayout:
        orientation: "horizontal"
        size_hint_x: .55 

        Label: 
            text: "Favori Renginiz"
            size_hint_x: .250

        Label:
            text: "Mavi"
            size_hint_x: .50
        CheckBox:
            group: "fov_color"
            value: root.mavi
            size_hint_x: .25

        Label:
            text: "Kirmizi"
            size_hint_x: .50

        CheckBox:
            group: "fov_color"
            value: root.kirmizi
            size_hint_x: .25

        Label:
            text: "Yesil"
            size_hint_x: .50
        CheckBox:
            group: "fov_color"
            value: root.yesil
            size_hint_x: .25

    BoxLayout:
        orientation: "horizontal"

        Label:
            text: str(slider_id.value)

        Slider:
            id: slider_id
            min: -100
            max: 100
            value: 0
            step: 1

        Switch:
            id: switch_id
            on_active: root.switch_on(self, self.active)

    BoxLayout:
        orientation: "horizontal"
        height: 20
        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .25

            Button:
                text: "Open Popup"
                on_press: root.open_popup()

        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .25

            Spinner:
                text: "Ac"
                values: ["Birinci","Ikinci","Ucuncu"]
                id: spinner_id
                on_text: root.spiner_clicked(spinner_id.text)
	    
"""




class popupcls(Popup):
    pass

class main2(BoxLayout):
    mavi = ObjectProperty(True)
    kirmizi = ObjectProperty(False)
    yesil = ObjectProperty(False)
    checkbox_is_active = ObjectProperty(False)

    def checkbox_18_clicked(self, nesne, value):

        if value == True:
            print("Açık")
	    
        else:
            print("Kapalı")


    def switch_on(self, instance, value):
        if value == True:
            print("Aktif")

        else:
            print("Pasif")
	    
    def open_popup(self):
        the_popup = popupcls()
        the_popup.open()

    def spiner_clicked(self, value):
        print("Spiner Value " + value)

class main(App):
    def build(self):
        self.app = Builder.load_string(kv)
        Window.clearcolor = (0,.5,.5,1)
        return main2()

if __name__ == "__main__":
    main().run()

ismail bey cevaplamıs ama olayı soyle dusunebilirsin:

hani biz python da deger atiyoruz ya,iste bunun kv dili versiyonunu dusun.Ben bir degeri kv dilinde kullanmak istersem properties leri kullanirim,onun gibi

yardimci olması baglamında iki ornek:

  • birinci ornek
  • ikinci ornek
from kivy.app import App 
from kivy.uix.boxlayout import BoxLayout 
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup 
from kivy.core.window import Window
from kivy.lang import Builder


kv = """
#:set mavi True
#:set kirmizi False
#:set yesil False
#:set checkbox_is_active False
<popupcls>:
    size_hint: .2,.3
    auto_dismiss: False
    title: "Uyarı"
    Button:
        text: "Close"
        on_press: root.dismiss()
        
<main2>: 
    orientation: "vertical"
    padding: 10
    spacing: 10

    BoxLayout:
        orientation: "horizontal"
        size_hint_x: .22

        Label:
            text: "Are You Over 18"
            size_hint_x: .80

	CheckBox:
	    on_active: root.checkbox_18_clicked(self, self.active)
	    size_hint_x: .60

    BoxLayout:
        orientation: "horizontal"
        size_hint_x: .55 

        Label: 
            text: "Favori Renginiz"
            size_hint_x: .250

        Label:
            text: "Mavi"
            size_hint_x: .50
        CheckBox:
            group: "fov_color"
            value: mavi # root.mavi yerine mavi
            size_hint_x: .25

        Label:
            text: "Kirmizi"
            size_hint_x: .50

        CheckBox:
            group: "fov_color"
            value: kirmizi # root.kirmizi yerine kirmizi
            size_hint_x: .25

        Label:
            text: "Yesil"
            size_hint_x: .50
        CheckBox:
            group: "fov_color"
            value: yesil # root.yesil yerine yesil
            size_hint_x: .25

    BoxLayout:
        orientation: "horizontal"

        Label:
            text: str(slider_id.value)

        Slider:
            id: slider_id
            min: -100
            max: 100
            value: 0
            step: 1

        Switch:
            id: switch_id
            on_active: root.switch_on(self, self.active)

    BoxLayout:
        orientation: "horizontal"
        height: 20
        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .25

            Button:
                text: "Open Popup"
                on_press: root.open_popup()

        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .25

            Spinner:
                text: "Ac"
                values: ["Birinci","Ikinci","Ucuncu"]
                id: spinner_id
                on_text: root.spiner_clicked(spinner_id.text)
	    
"""




class popupcls(Popup):
    pass

class main2(BoxLayout):
    """
    mavi = ObjectProperty(True)
    kirmizi = ObjectProperty(False)
    yesil = ObjectProperty(False)
    checkbox_is_active = ObjectProperty(False)
    """
    def checkbox_18_clicked(self, nesne, value):

        if value == True:
            print("Açık")
	    
        else:
            print("Kapalı")


    def switch_on(self, instance, value):
        if value == True:
            print("Aktif")

        else:
            print("Pasif")
	    
    def open_popup(self):
        the_popup = popupcls()
        the_popup.open()

    def spiner_clicked(self, value):
        print("Spiner Value " + value)

class main(App):
    def build(self):
        self.app = Builder.load_string(kv)
        Window.clearcolor = (0,.5,.5,1)
        return main2()

if __name__ == "__main__":
    main().run()
1 Beğeni