沿着在树莓派中开发瘦客户端链接远程桌面GUI程序这条主线,摸到了这里,使用pyqt5开发图形界面以后,程序读取一个ini配置文件,将远程链接的相关参数写到这个ini配置文件中。这样能够实现一个最简版的远程桌面链接程序。python
以上是背景,仅作一个记录。bash
此文参考了这个网址:app
https://blog.csdn.net/songlh1234/article/details/83316468 ide
在config下有一个config.ini配置文件ui
# 定义config分组 [config] platformName=Android appPackage=com.romwe appActivity=com.romwe.SplashActivity # 定义cmd分组 [cmd] viewPhone=adb devices startServer=adb start-server stopServer=adb kill-server install=adb install aaa.apk id=1 weight=12.1 isChoice=True # 定义log分组 [log] log_error=true
在test_config.py中编写读取配置文件的脚本代码spa
import configparser # 实例化configParser对象 config = configparser.ConfigParser() # -read读取ini文件 config.read('C:\\Users\\songlihui\\PycharmProjects\\AutoTest_02\\config\\config.ini', encoding='GB18030') # -sections获得全部的section,并以列表的形式返回 print('sections:' , ' ' , config.sections()) # -options(section)获得该section的全部option print('options:' ,' ' , config.options('config')) # -items(section)获得该section的全部键值对 print('items:' ,' ' ,config.items('cmd')) # -get(section,option)获得section中option的值,返回为string类型 print('get:' ,' ' , config.get('cmd', 'startserver')) # -getint(section,option)获得section中的option的值,返回为int类型 print('getint:' ,' ' ,config.getint('cmd', 'id')) print('getfloat:' ,' ' , config.getfloat('cmd', 'weight')) print('getboolean:' ,' ', config.getboolean('cmd', 'isChoice')) """ 首先获得配置文件的全部分组,而后根据分组逐一展现全部 """ for sections in config.sections(): for items in config.items(sections): print(items)
执行结果:.net
C:\Users\think\.virtualenvs\RDPGUI-Oi_XG-yi\Scripts\python.exe D:/树莓派开发/RDPGUI/test/test_config.py sections: ['config', 'cmd', 'log'] options: ['platformname', 'apppackage', 'appactivity'] items: [('viewphone', 'adb devices'), ('startserver', 'adb start-server'), ('stopserver', 'adb kill-server'), ('install', 'adb install aaa.apk'), ('id', '1'), ('weight', '12.1'), ('ischoice', 'True')] get: adb start-server getint: 1 getfloat: 12.1 getboolean: True ('platformname', 'Android') ('apppackage', 'com.romwe') ('appactivity', 'com.romwe.SplashActivity') ('viewphone', 'adb devices') ('startserver', 'adb start-server') ('stopserver', 'adb kill-server') ('install', 'adb install aaa.apk') ('id', '1') ('weight', '12.1') ('ischoice', 'True') ('log_error', 'true') Process finished with exit code 0