Table Of Contents
Configuration object¶
The Config
object is an instance of a modified Python ConfigParser.
See the ConfigParser documentation for more information.
Kivy has a configuration file which determines the default settings. In order to change these settings, you can alter this file manually or use the Config object. Please see the Configure Kivy(翻訳済み) section for more information.
Applying configurations¶
Configuration options control the initialization of the App
.
In order to avoid situations where the config settings do not work or are not
applied before window creation (like setting an initial window size),
Config.set
should be used before
importing any other Kivy modules. Ideally, this means setting them right at
the start of your main.py script.
Alternatively, you can save these settings permanently using
Config.set
then
Config.write
. In this case, you will need to
restart the app for the changes to take effect. Note that this approach will
effect all Kivy apps system wide.
Usage of the Config object¶
To read a configuration token from a particular section:
>>> from kivy.config import Config
>>> Config.getint('kivy', 'show_fps')
0
Change the configuration and save it:
>>> Config.set('postproc', 'retain_time', '50')
>>> Config.write()
For information on configuring your App
, please see the
Application configuration (アプリの設定) section.
バージョン 1.7.1 で変更: The ConfigParser should work correctly with utf-8 now. The values are converted from ascii to unicode only when needed. The method get() returns utf-8 strings.
Available configuration tokens¶
kivy: |
|
---|---|
postproc: |
|
graphics: |
default_font: list, defaults to [‘Roboto’, ‘data/fonts/Roboto-Regular.ttf’, ‘data/fonts/Roboto-Italic.ttf’, ‘data/fonts/Roboto-Bold.ttf’, ‘data/fonts/Roboto-BoldItalic.ttf’]
|
input: | You can create new input devices using this syntax: # example of input provider instance
yourid = providerid,parameters
# example for tuio provider
default = tuio,127.0.0.1:3333
mytable = tuio,192.168.0.1:3334
参考 Check the providers in |
widgets: |
|
modules: | You can activate modules with this syntax: modulename =
Anything after the = will be passed to the module as arguments. Check the specific module’s documentation for a list of accepted arguments. |
バージョン 1.10.0 で変更: min_state_time and allow_screensaver have been added to the graphics section. kivy_clock has been added to the kivy section. default_font has beed added to the kivy section.
バージョン 1.9.0 で変更: borderless and window_state have been added to the graphics section. The fake setting of the fullscreen option has been deprecated, use the borderless option instead. pause_on_minimize has been added to the kivy section.
バージョン 1.8.0 で変更: systemanddock and systemandmulti has been added as possible values for keyboard_mode in the kivy section. exit_on_escape has been added to the kivy section.
バージョン 1.2.0 で変更: resizable has been added to graphics section.
バージョン 1.1.0 で変更: tuio no longer listens by default. Window icons are not copied to
user directory anymore. You can still set a new window icon by using the
window_icon
config setting.
バージョン 1.0.8 で変更: scroll_timeout, scroll_distance and scroll_friction have been added. list_friction, list_trigger_distance and list_friction_bound have been removed. keyboard_type and keyboard_layout have been removed from the widget. keyboard_mode and keyboard_layout have been added to the kivy section.
-
kivy.config.
Config
= None¶ The default Kivy configuration object. This is a
ConfigParser
instance with thename
set to ‘kivy’.Config = ConfigParser(name='kivy')
-
class
kivy.config.
ConfigParser
(name='')[ソース]¶ ベースクラス:
configparser.RawConfigParser
,builtins.object
Enhanced ConfigParser class that supports the addition of default sections and default values.
By default, the kivy ConfigParser instance,
Config
, is named ‘kivy’ and the ConfigParser instance used by theApp.build_settings
method is named ‘app’.Parameters: - name: string
The name of the instance. See
name
. Defaults to ‘’.
バージョン 1.9.0 で変更: Each ConfigParser can now be
named
. You can get the ConfigParser associated with a name usingget_configparser()
. In addition, you can now control the config values withConfigParserProperty
.バージョン 1.0.7 で追加.
-
add_callback
(callback, section=None, key=None)[ソース]¶ Add a callback to be called when a specific section or key has changed. If you don’t specify a section or key, it will call the callback for all section/key changes.
Callbacks will receive 3 arguments: the section, key and value.
バージョン 1.4.1 で追加.
-
static
get_configparser
(name)[ソース]¶ Returns the
ConfigParser
instance whose name is name, or None if not found.Parameters: - name: string
The name of the
ConfigParser
instance to return.
-
getdefault
(section, option, defaultvalue)[ソース]¶ Get the value of an option in the specified section. If not found, it will return the default value.
-
getdefaultint
(section, option, defaultvalue)[ソース]¶ Get the value of an option in the specified section. If not found, it will return the default value. The value will always be returned as an integer.
バージョン 1.6.0 で追加.
-
name
¶ The name associated with this ConfigParser instance, if not ‘’. Defaults to ‘’. It can be safely changed dynamically or set to ‘’.
When a ConfigParser is given a name, that config object can be retrieved using
get_configparser()
. In addition, that config instance can also be used with aConfigParserProperty
instance that set its config value to this name.Setting more than one ConfigParser with the same name will raise a ValueError.
-
read
(filename)[ソース]¶ Read only one filename. In contrast to the original ConfigParser of Python, this one is able to read only one file at a time. The last read file will be used for the
write()
method.バージョン 1.9.0 で変更:
read()
now calls the callbacks if read changed any values.
-
remove_callback
(callback, section=None, key=None)[ソース]¶ Removes a callback added with
add_callback()
.remove_callback()
must be called with the same parameters asadd_callback()
.Raises a ValueError if not found.
バージョン 1.9.0 で追加.
-
set
(section, option, value)[ソース]¶ Functions similarly to PythonConfigParser’s set method, except that the value is implicitly converted to a string.
-
setall
(section, keyvalues)[ソース]¶ Sets multiple key-value pairs in a section. keyvalues should be a dictionary containing the key-value pairs to be set.
-
setdefault
(section, option, value)[ソース]¶ Set the default value for an option in the specified section.
-
setdefaults
(section, keyvalues)[ソース]¶ Set multiple key-value defaults in a section. keyvalues should be a dictionary containing the new key-value defaults.