Kivy popup penceresi

kivy de bir ders videosun da yazdıgım bu kodların popup kısmında hata var ama bir türlü hatayı bulamadım.
bide şu objectpropert kullanmış bu ne işe yarıyor acaba anlamadım da :blush:


main.py

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 
class popupcls(Popup):
	pass

class main2(BoxLayout):
	checkbox_is_active = ObjectProperty(False)
	mavi = ObjectProperty(True)
	kirmizi = ObjectProperty(False)
	yesil = 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):
		Window.clearcolor = (0,.5,.5,1)
		return main2()

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

main.kv

<popup_cls>:
	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)

Kivy konusunda pek bilgim yok ama ObjectProperty dediği şey True, False, 1, 'Merhaba', vb. nesneleri kapsayan, bunlar yerine geçebilen, kendi içinde bunları yöneten bir yapı olsa gerek. Şu ifadeyi bir nevi False gibi düşünebilirsiniz: ObjectProperty(False)

2 Beğeni

Daha sorunu cozemedim ama sorunun kaynaklarından biri yine kv stringinin veya main.kv dosyasının Builder ile yuklenmemesi!!!

Ben burada bosuna mı kv dosyası yuklenecek dedim o kadar!!!Lutfen biraz daha anlayısss.

Bu arada sorununu cozebilirsem yazmaya calısırım.

Aslında yazmayacaktım ama iste vaziyet ortada.

1 Beğeni

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

Cevap için teşşekür ederim. :slight_smile: Bidakine kv yi py nin içinde kullanırım.

Yukarıda anlattıgımı dusunuyorum ama eksik anlattiksa affola.

Niye ise yaramasın ki,adamlar onu bosuna yapmamıs ki.

kivy çok iyimi biliyorsun :smiley:

Yok kivy yi cok iyi bildigimden oturu degil,bu forumda benden cok daha iyi kivyi bilen var.Hatta bu forumda @Ethnic diye biri play store a uygulama yaptı.Ben de okulda basit bir wallpaper uygulaması yapıyordum,ama bilmem akıbeti ne olur.

Ben bu wallpaper uygulamasını yapmaya calısırken karsıma oyle sorunlar cıktı ki,bazılarını internette bile bulamadım,kaynak kodlarından cozmeye calıstım isi.

Şuan kendin yaptıgın bir program varmı veya devam eden?

Var,yukarıda bahsettigim wallpaper uygulaması:

kodları sonra guncelleyecegim,buyuk bir guncelleme olacak bu,katılmak isteyen herkes katılabilir,memnuniyet duyarım,bu arada o kadar cok dosya olmasına bakma,benim yazdıgım bir script dosyası,birkac txt dosyasi felan.

aslında illa kv yi py icinde kullanmanız gerekmez,main.kv dosyasını olusturup aynı dizindeki scriptinize Builder.load_file ile yukleyebilirsiniz.

app sınıfının ismi ile kv dosyasının ismi aynı olunca da çalışıyor. :slight_smile:

1 Beğeni

Bak ben bunu ya unutmustum,ya da bilmiyordum,ogrettigin icin gercekten tesekkur ederim.

1 Beğeni

bide yaşın kaçdı senin? :smiley:

16 yasındayım ben,lise 2 yi bitirecegim allahın izniyle.

GÜZEL bende az kalsın devamsılıkdan kalıyordum 2 gün önce 12 ye geçdim bende. ne zaman başladın yazılma ?

instagram kullanıyorsan ordan eklerim :slight_smile:

benden erken başlamışsın bende 6-7 ay oldu.

bende facebook kullanmıyorum :sweat_smile:

1 Beğeni

sistenin ismi python türkiye mi???