Having an issue here trying to remove widget from a pop up menu.

239 views
Skip to first unread message

Computer Science

unread,
Jun 29, 2022, 2:58:58 AM6/29/22
to Kivy users support
Python File

import kivy
from kivy.app import App
from kivymd.app import MDApp
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager,Screen
from kivymd.uix.card import MDCard,MDCardSwipe
from kivymd.uix.picker import MDTimePicker,MDDatePicker
from kivy.uix.scrollview import ScrollView
from kivymd.uix.list import MDList,TwoLineListItem
from kivymd.uix.screen import Screen




Window.size = (428 , 635)


class Login(Screen):
    pass

class Signup(Screen):
    pass

class CustomWidget(BoxLayout):
    def remove(self):
        self.parent.remove_widget(self)

 
class SwipeWidget(MDCardSwipe):
    def remove(self):
        self.parent.remove_widget(self)



class Menu(Screen):

    def __init__(self,**kwargs):
        super(Menu,self).__init__(**kwargs)



    def add_note(self):
    #    scroll = ScrollView()
        customwidget = CustomWidget()
        #list_view = MDList()
    #    scroll.add_widget(list_view)
    #    new_btn= OneLineListItem(text='hi')
        #list_view.add_widget(customwidget)

        self.ids.note_container.add_widget(customwidget)

    def add_event(self):
        eventwidget = EventWidget()
        swipewidget = SwipeWidget()
        self.ids.calendar_id.add_widget(eventwidget)
       
        self.ids.calendar_container.add_widget(swipewidget)

    def remove_list_item(self):
        self.ids.md_list.list_item.remove_widget(self)

   


class EventWidget(Screen):

   
   

    def on_save(self,instance,value,date_range):
        self.ids.date_id.text = str(value)

    def get_time(self,instance,time):
        self.ids.time_id.text = str(time)

    def pick_date(self):
        date_dialog = MDDatePicker()
        date_dialog.bind(on_save = self.on_save)
        date_dialog.open()


    def pick_time(self):
        time_dialog = MDTimePicker()
        time_dialog.bind(time = self.get_time)
        time_dialog.open()

    def remove(self, *kargs):    
        self.children.remove_widget()

       
    def save_event(self):
        self.parent.remove_widget(self)


   


# Designate the .kv(tabs.kv) design file , use this when we want to create  kv file which link to he





#creating app
class MyApp(MDApp,App):
    #def build(self):
        #return Label(text = 'Interface')  #create a label
    def build(self):
        self.theme_cls.theme_style = "Dark"
        Builder.load_file('register.kv')
        Builder.load_file('menu.kv')
       

        sm = ScreenManager()


        sm.add_widget(Login(name = "login"))
        sm.add_widget(Signup(name = "signup"))
        sm.add_widget(Menu(name = "menu"))



        return sm

   

       



if __name__ == '__main__':  
    #Signup().run()
    #Login().run()
    MyApp().run()
       #run app, type python my_app.py in pip to run

KIVY FILE


<CustomWidget>
    size_hint_y:1.0
    size_hint_x:1.0
    size_hint_y:None
    TextInput:
        id: textinput1
    Button:
        size_hint_y:0.3
        size_hint_x:0.3
        text:'remove'
        on_press:root.remove()



<SwipeWidget>:
    size_hint_y:1.0
    size_hint_x:1.0
    size_hint_y:None

    MDCardSwipeLayerBox:
        MDIconButton:
            icon: "trash-can"
            pos_hint: {"center_y": .5}
            on_press: root.remove()

    MDCardSwipeFrontBox:

        TwoLineListItem:
            id: list_item
            text:'event'
            secondary_text:'subsu'





<EventWidget>
    MDCard:
        id : event_id
        size_hint:None, None
        size:320, 400
        pos_hint : {'center_x':.5,'center_y':.5}
        elevation :15
        md_bg_color : [14/255,50/255,71/255,1]
        padding:20
        spacing:30
        orientation :'vertical'

        MDLabel:
            text:"New event"
            halign:'center'
            font_style : 'Button'
            font_size :35

        TextInput:
            id:event_title
            hint_text : 'Title'

        TextInput:
            id:event_description
            hint_text :'Description'

        MDRectangleFlatButton :
            id:date_id
            text : 'Add date'
            pos_hint : {'center_x':.5}
            font_size : 15
            on_press:root.pick_date()

        MDRectangleFlatButton :
            id:time_id
            text : 'Add time'
            pos_hint : {'center_x':.5}
            font_size : 15
            on_press:root.pick_time()

        MDRectangleFlatButton :
            text : 'Save event'
            pos_hint : {'center_x':.5}
            font_size : 15
            on_press:
                root.save_event()
                #root.ids.list_item.text = root.ids.event_title


           

        MDRectangleFlatButton :
            text : 'Cancel'
            pos_hint : {'center_x':.5}
            font_size : 15
            on_press: root.remove()




                 
               
       





   
<Menu>:
    MDScreen:
        md_bg_color : [59/255,139/255,137/255,1]
        MDBottomNavigation:
           
            text_color_active: 0, 0, 0, 1
            MDBottomNavigationItem:
                name: 'menu'
                text: 'Menu'
                icon: 'home'
                badge_icon: "numeric-10"
               

                MDCard:
                    size_hint:None, None
                    size:350, 100
                    pos_hint : {'center_x':.3,'center_y':.9}
                    elevation :15
                    md_bg_color : [14/255,50/255,71/255,1]
                    padding:50
                    spacing:30
                    orientation :'vertical'

                    MDLabel:
                        text:"Menu"
                        halign:'center'
                        font_style : 'Button'
                        font_size :35


            MDBottomNavigationItem:
                name: ' note'
                text: 'Note'
                icon: 'note'
                id:note_id
                badge_icon: "numeric-5"

                GridLayout:
                   
                    size_hint_y:0.8
                    id :note_container

           

                MDCard:
                    size_hint:None, None
                    size:350, 100
                    pos_hint : {'center_x':.3,'center_y':.9}
                    elevation :15
                    md_bg_color : [14/255,50/255,71/255,1]
                    padding:50
                    spacing:30
                    orientation :'vertical'

                    MDLabel:
                        text:"Note"
                        halign:'center'
                        font_style : 'Button'
                        font_size :35

                MDIconButton:
                    icon: "clipboard-plus"
                    pos:340,480
                    on_press:root.add_note()

               
                   
                   

                           
                   

                   
                       


            MDBottomNavigationItem:
                name: 'calendar'
                text: 'Calendar'
                icon: 'calendar'
                id :calendar_id

                GridLayout:
                    cols:1
                    size_hint_y:1
                    id :calendar_container

                    MDList:
                        id: md_list
                        padding: 0


               

                MDCard:
                    size_hint:None, None
                    size:350, 100
                    pos_hint : {'center_x':.3,'center_y':.9}
                    elevation :15
                    md_bg_color : [14/255,50/255,71/255,1]
                    padding:50
                    spacing:30
                    orientation :'vertical'

                    MDLabel:
                        text:"Calendar"
                        halign:'center'
                        font_style : 'Button'
                        font_size :35

                MDIconButton:
                    icon: "clipboard-plus"
                    pos:340,480
                    on_press: root.add_event()

               



               



            MDBottomNavigationItem:
                name: 'message'
                text: 'Message'
                icon: 'message'


                MDCard:
                    size_hint:None, None
                    size:350, 100
                    pos_hint : {'center_x':.3,'center_y':.9}
                    elevation :15
                    md_bg_color : [14/255,50/255,71/255,1]
                    padding:50
                    spacing:30
                    orientation :'vertical'

                    MDLabel:
                        text:"Chat"
                        halign:'center'
                        font_style : 'Button'
                        font_size :35


            MDBottomNavigationItem:
                name: 'setting'
                text: 'Setting'
                icon: 'setting'


                MDCard:
                    size_hint:None, None
                    size:320, 400
                    pos_hint : {'center_x':.5,'center_y':.5}
                    elevation :15
                    md_bg_color : [14/255,50/255,71/255,1]
                    padding:20
                    spacing:30
                    orientation :'vertical'

                    MDLabel:
                        text:"Setting"
                        halign:'center'
                        font_style : 'Button'
                        font_size :35

                    MDRectangleFlatButton :
                        text : 'LOG-OUT'
                        pos_hint : {'center_x':.5}
                        font_size : 15
                        on_release:
                            app.root.current = 'login'
                             
                            app.root.transition.direction = 'up'
                    Widget :
                        size_hint_y :None
                        height :30




                   



       

       
        

Elliot Garbus

unread,
Jun 29, 2022, 12:26:23 PM6/29/22
to kivy-...@googlegroups.com

I don’t see a Popup in the code.   The code also seems to be missing the kv definitions for login and signup.

 

Please be clear about the issue you have having, and share a minimal runnable example.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/98d2ebe4-9da1-40d9-9e23-8e1385953e39n%40googlegroups.com.

 

Computer Science

unread,
Jun 29, 2022, 11:46:04 PM6/29/22
to Kivy users support
Surely.

I am only working on the front end for now hence just doing the clicking and navigation.

So when you run the application it works, you will get the screen below

screen1.JPG
Click Login and no code is done to check this for now and this will take you to the home page like below

screen2.JPG

Click on CALENDAR and you will go to that section

screen3.JPG

CLICK THE + sign to right corner to add an event at this point the pop up menu will appear like below

screen4.JPG
And an event will be added to the main screen like above BUT when I press Cancel I want the event to be removed but the event stays like the image below.

The questions is how do I remove that event in the main screen when the Cancel button is clicked. Thank you.

screen5.JPG

Elliot Garbus

unread,
Jun 29, 2022, 11:52:11 PM6/29/22
to kivy-...@googlegroups.com

how do I remove that event in the main screen when the Cancel button is clicked

 

From the layout that contains the event entry, call remove_widget(), and pass in the widget to remove.

 

 

From: Computer Science
Sent: Wednesday, June 29, 2022 8:46 PM
To: Kivy users support
Subject: Re: [kivy-users] Having an issue here trying to remove widget from apopup menu.

 

Surely.

 

I am only working on the front end for now hence just doing the clicking and navigation.

 

So when you run the application it works, you will get the screen below

 

Click Login and no code is done to check this for now and this will take you to the home page like below

 

 

Click on CALENDAR and you will go to that section

 

 

CLICK THE + sign to right corner to add an event at this point the pop up menu will appear like below

 

And an event will be added to the main screen like above BUT when I press Cancel I want the event to be removed but the event stays like the image below.

 

The questions is how do I remove that event in the main screen when the Cancel button is clicked. Thank you.

 

screen4.JPG
screen5.JPG
screen2.JPG
screen3.JPG
screen1.JPG
Reply all
Reply to author
Forward
0 new messages