鱼C论坛

 找回密码
 立即注册
查看: 5593|回复: 2

[已解决]关于easygui 里的 用户配置 EgStore 的用法

[复制链接]
发表于 2017-5-11 23:29:23 | 显示全部楼层 |阅读模式
50鱼币
其实鱼老师的例子我大约能理解,但还是不会用这个类,0基础初学者,经常卡在一些细节问题上,希望有时间的高手们能给我写个连贯的示例,万分感谢!!!
这是鱼老师的例子:
下面是创建一个"设置"类的例子:
#-----------------------------------------------------------------------
# create "settings", a persistent Settings object
# Note that the "filename" argument is required.
# The directory for the persistent file must already exist.
#-----------------------------------------------------------------------
settingsFilename = os.path.join("C:", "FishCApp", "settings.txt")  # Windows example
settings = Settings(settingsFilename)

下面是使用"设置"对象的例子:
# we initialize the "user" and "server" variables
# In a real application, we'd probably have the user enter them via enterbox
user    = "奥巴马"
server  = "白宫"

# we save the variables as attributes of the "settings" object
settings.userId = user
settings.targetServer = server
settings.store()    # persist the settings

# run code that gets a new value for userId
# then persist the settings with the new value
user    = "小甲鱼"
settings.userId = user
settings.store()
最佳答案
2017-5-11 23:29:24
刚好学到这里,搜了一些大神们的解答,但是还是有一点乱码问题没有解决
开始要导入一些必须的模块
#-*- coding:utf-8 -*-
from easygui import *
import pickle
import os
#创建Settings类
class Settings(EgStore):
    def __init__(self,filename):    #下划线不对会报:object() takes no parameters
        self.userId =""
        self.targetServer=""
        self.filename = filename

#后面大致跟教程里的一样

settingsFilename = "c:\\test\\settings.txt"  #保存数据的文件路径,感觉使用这个更简单
settings = Settings(settingsFilename)

print("3")  #调试用的,忽略
user = "奥巴马"
server = "白宫"
settings.userId = user
settings.targetServer = server
settings.store()                        
#到了这里就可以在c:\test\settings.txt 看到保存的数据,我这是显示乱码,还知道为什么 还没弄明白
#下面是不打开文本直接打印出来
f = open(settingsFilename,'rb')  #这里的读取模式要使用‘rb’不然会报错
lines = f.readlines()
for line in lines:
    print (line)
f.close()

最佳答案

查看完整内容

刚好学到这里,搜了一些大神们的解答,但是还是有一点乱码问题没有解决 开始要导入一些必须的模块 #-*- coding:utf-8 -*- from easygui import * import pickle import os #创建Settings类 class Settings(EgStore): def __init__(self,filename): #下划线不对会报:object() takes no parameters self.userId ="" self.targetServer="" self.filename = filename #后面大致跟教程里 ...
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-5-11 23:29:24 | 显示全部楼层    本楼为最佳答案   
刚好学到这里,搜了一些大神们的解答,但是还是有一点乱码问题没有解决
开始要导入一些必须的模块
#-*- coding:utf-8 -*-
from easygui import *
import pickle
import os
#创建Settings类
class Settings(EgStore):
    def __init__(self,filename):    #下划线不对会报:object() takes no parameters
        self.userId =""
        self.targetServer=""
        self.filename = filename

#后面大致跟教程里的一样

settingsFilename = "c:\\test\\settings.txt"  #保存数据的文件路径,感觉使用这个更简单
settings = Settings(settingsFilename)

print("3")  #调试用的,忽略
user = "奥巴马"
server = "白宫"
settings.userId = user
settings.targetServer = server
settings.store()                        
#到了这里就可以在c:\test\settings.txt 看到保存的数据,我这是显示乱码,还知道为什么 还没弄明白
#下面是不打开文本直接打印出来
f = open(settingsFilename,'rb')  #这里的读取模式要使用‘rb’不然会报错
lines = f.readlines()
for line in lines:
    print (line)
f.close()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-6-23 16:06:46 | 显示全部楼层
阿凡提水 发表于 2017-5-11 23:29
刚好学到这里,搜了一些大神们的解答,但是还是有一点乱码问题没有解决
开始要导入一些必须的模块
#-*- c ...

非常感谢你的耐心回答
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-12 19:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表