简体   繁体   中英

kivy config.ini file not read when system reboot

I am running kivy-kivymd on embedded linux. The purpose of my work is to automatically restart the same python file with a script I wrote in the rc5.d folder when the system reboots. The problem is that it ignores the config.ini I've changed the first time it runs. When I kill the process and run the same file manually, I can see the changes.

How can I get it to read the config.ini file when the system reboots?

run scripts:

case "$1" in
    start|"")   
                
             cd /home/root/mykivydirect
             python3 main.py &

        ;;
    stop)
                ;;
    *)
        echo "Usage: guistart {start|stop}" >&2
        exit 1
        ;;
esac

exit 0

main.py

import os

os.environ['KIVY_GL_BACKEND'] = 'sdl2'
#os.environ['KIVY_KEYBOARD_MODE'] = 'dock'
#os.environ['GRAPHICS_ROTATION'] = '180'
#os.environ['GRAPHICS_SHOW_CURSOR'] = '0'


from kivy.config import Config
import os.path                                                                
                                                                                
def get_config_file_name():                                                     
    # return any file name here                                                 
    return os.path.join(os.path.expanduser('~/mykivydirect'), 'config.ini')        

#from kivy.config import Config
                                                                                
Config.read(get_config_file_name())  

I solved my problem using these codes:

from kivy.config import Config                                                  

Config.set('kivy','keyboard_mode', 'dock')
Config.set('graphics', 'rotation', '180')
Config.set('graphics', 'show_cursor', '0')
Config.write()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM