基本上,我对python和kivy非常陌生,并试图创建一个计时器应用程序,在20分钟后发出通知,让您的眼睛休息。我使用plyer来设置通知,我在mac上。通常,由于pyobjus错误,通知不起作用,但我做了相应的工作。但现在我有了这个新的错误。
运行文件(‘/用户/燕麦/下载/叶1.0/源代码/叶0.6 . .py',wdir=’/Users/oats/下载/叶1.0/源代码‘)回溯(最近一次调用):
在LeafApp(MDApp)类中,文件“/Users/oats/下载/ line 1.0/源代码/line 0.6 MDApp”,第218行:
在LeafApp notifyMe中,文件“/Users/燕麦/下载/ line 1.0/源代码/LEAF 0.6 notifyMe”,第240行(嘿,您!休息一下!),“您应该遵循20-20-20规则,以保持眼睛健康”)。
在notifyMe notification.notify中,文件“/Users/燕麦/下载/ line 1.0/源代码/LEAF 0.6 notification.notify”,第231行
文件"/Users/oats/opt/anaconda3/lib/python3.8/site-packages/plyer/facades/notification.py",第79行,在通知self._notify(
文件"/Users/oats/opt/anaconda3/lib/python3.8/site-packages/plyer/platforms/macosx/notification.py",第38行,在通知usrnotifctr.setDelegate(自我)
AttributeError: NoneType对象没有属性“setDelegate_”
是完整的错误消息。我的密码在下面。
“”“
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.picker import MDDatePicker
from kivymd.uix.picker import MDThemePicker
from kivy.config import Config
from kivy.uix.boxlayout import BoxLayout
from kivymd.theming import ThemableBehavior
from kivymd.uix.list import MDList
from kivy.properties import ObjectProperty
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivy.properties import StringProperty, ListProperty
from kivy.lang import Builder
from kivy.core.window import Window
from plyer import notification
import time
import plyer
Config.set('graphics', 'width', '1600')
Config.set('graphics', 'height', '1200')
KV = '''
<Box@BoxLayout>:
    bg: .65, .48, .35, 1 
       
             
BoxLayout:
    Rectangle:    
        size: 1600, 1200
    Box:
        bg: app.theme_cls.bg_light
    Box:
        bg: app.theme_cls.bg_normal
    Box:
        bg: app.theme_cls.bg_dark
    Box:
        bg: app.theme_cls.bg_darkest
            
'''
            
screen_helper = """
ScreenManager:
    MenuScreen:
    HomeScreen:
    BreakScreen:
    SettingsScreen
        
<MenuScreen>:
    name: 'menu'
    
  
        
    MDLabel:
        rectangle:
        background_color: .65, .48, .35, 1           
        size: 300, 700
        pos_hint: {'center_x':0.1, 'center_y':0.0}
        
                
    MDLabel:
        text: "Welcome to"
        font_style: 'H2'
        size:500, 500
        pos_hint: {'center_x':0.95,'center_y':0.84}
        
    MDLabel:
        text: "LEAF"
        font_style: 'H3'
        size:500, 500
        pos_hint: {'center_x':1.045,'center_y':0.7}
        
        
    MDFlatButton:
        text: 'Calendar'
        font_style: 'H6'
        pos_hint: {'center_x':0.091,'center_y':0.65}
        on_release: app.show_date_picker()
            
            
    MDFlatButton:
        text: 'Home'
        font_style: 'H6'
        pos_hint: {'center_x':0.076,'center_y':0.57}
        on_press: root.manager.current = 'home'
        
    MDFlatButton:
        text: 'Settings'
        font_style: 'H6'
        pos_hint: {'center_x':0.09,'center_y':0.49}
        on_press: root.manager.current = 'settings'
        
            
    MDRectangleFlatButton:
        text: 'Continue'
        font_style: 'H6'
        pos_hint: {'center_x':0.61,'center_y':0.345}
        on_press: root.manager.current = 'home'
   
    
<HomeScreen>:
    name: 'home'    
                
        
    MDToolbar:
        id: toolbar
        title: "Home
        pos_hint: {"top": 1}
        elevation: 5
        left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
        
    Widget:
        MDNavigationDrawer:
            id: nav_drawer
    
            ContentNavigationDrawer:
                orientation: 'vertical'
                padding: "8dp"
                spacing: "8dp"
                
                MDFlatButton:
                    text: 'Return to menu'
                    font_style: 'Subtitle1'
                    on_release: root.manager.current = 'menu'
                MDFlatButton:
                    text: 'Open Calendar'
                    font_style: 'Subtitle1'
                    on_release: app.show_date_picker()
                    
                MDFlatButton:
                    text: 'Open Settings'
                    font_style: 'Subtitle1'
                    on_press: root.manager.current = 'settings'
    
                    
                    
                            
                
                
            
    
<BreakScreen>:
    name: 'break'
    
<SettingsScreen>:
    name: 'settings'
    
    
    MDFlatButton:
        text: 'Return to menu'
        font_style: 'H6'
        pos_hint: {'center_x':0.1,'center_y':0.05}
        on_press: root.manager.current = 'menu'
        
    MDFlatButton:
        text: 'Change Theme'
        font_style: 'H6'
        pos_hint: {'center_x':0.85,'center_y':0.95}
        on_release: app.show_theme_picker() 
        
    MDFloatingActionButton:
        icon: 'moon-waning-crescent'
        theme_text_color: "Custom"
        md_bg_color: 0, 0.039, 0.867, 0.557
        pos_hint: {'center_x':0.9,'center_y':0.3}
        on_press: self.theme_cls.theme_style = "Dark"  # "Light"
        
    MDFloatingActionButton:
        icon: 'MDFloatingActionButton'
        icon: 'lightbulb'
        pos_hint: {'center_x':0.9,'center_y':0.1}
        on_press: self.theme_cls.theme_style = "Light"  # "Dark"
        
        
"""  
class MenuScreen(Screen):
    pass
class HomeScreen(Screen):
    pass
class BreakScreen(Screen):
    pass
class SettingsScreen(Screen):
    pass
class ContentNavigationDrawer(BoxLayout):
    pass
class DrawerList(ThemableBehavior, MDList):
    pass
    
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(HomeScreen(name='profile'))
sm.add_widget(BreakScreen(name='upload'))
sm.add_widget(SettingsScreen(name='settings'))
class LeafApp(MDApp):
    
    def show_date_picker(self):
        date_dialog = MDDatePicker()
        date_dialog.open()
    def show_theme_picker(self):
        theme_dialog = MDThemePicker()
        theme_dialog.open()
    def notifyMe(ttle, msg):
        notification.notify(
            title = ttle,
            message = msg,
            timeout = 10,
    )
    if __name__ == '__main__':
        while True:
            notifyMe("Hey You! take a break now !!", "You should follow the 20-20-20 rule to keep your eyes healthy")
            time.sleep(1200)
            
    def build(self):
        screen = Builder.load_string(screen_helper)
        return screen
    
LeafApp().run()
'''再次感谢任何人伸出援助之手。我完全糊涂了,需要帮助!
发布于 2021-05-14 20:09:29
尝试对代码进行轻微重构,如下所示:
def notifyMe(self, ttle, msg):  # added "self" arg
    notification.notify(
        title=ttle,
        message=msg,
        timeout=10,
    )
def timer_loop(self):
    while True:
        self.notifyMe("Hey You! take a break now !!", "You should follow the 20-20-20 rule to keep your eyes healthy")
        time.sleep(1200)
def build(self):
    # run timer as a separate thread
    threading.Thread(target=self.timer_loop, daemon=True).start()
    screen = Builder.load_string(screen_helper)
    return screenhttps://stackoverflow.com/questions/67530640
复制相似问题