[Python] 纯文本查看 复制代码 # -*- coding:utf-8 -*-
import json
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='TEST', size=(400, 300), name='frame', style=541072384)
self.Config = {}
self.initJsonObj()
self.启动窗口 = wx.Panel(self)
self.Centre()
self.组合框1 = wx.ComboBox(self.启动窗口, value='', pos=(34, 26), name='comboBox', choices=self.Config["组合框1"],
style=16)
self.组合框1.SetSize((112, 23))
self.组合框2 = wx.ComboBox(self.启动窗口, value='', pos=(34, 71), name='comboBox', choices=self.Config["组合框2"],
style=16)
self.组合框2.SetSize((116, 26))
self.组合框3 = wx.ComboBox(self.启动窗口, value='', pos=(37, 114), name='comboBox', choices=self.Config["组合框3"],
style=16)
self.组合框3.SetSize((119, 27))
def initJsonObj(self):
# 设置以utf-8解码模式读取文件,encoding参数必须设置,否则默认以gbk模式读取文件,当文件中包含中文时,会报错
f = open("config.json", encoding="utf-8")
self.Config = json.load(f)
'''
想在这块加一段代码,从文件里读取
'''
class myApp(wx.App):
def OnInit(self):
self.frame = Frame()
self.frame.Show(True)
return True
if __name__ == '__main__':
app = myApp()
app.MainLoop()
config.json:
[Asm] 纯文本查看 复制代码 {
"组合框1": ["北京", "上海", "天津"],
"组合框2": ["男", "女", "老", "少"],
"组合框3": ["美女", "帅哥", "丑八怪"]
} |