プログラムを開き、いくつかのトグルボタンをクリックし、トグルボタンを保存してから、もう一度開くと、ファイルから読み取り、同じボタンをトグルして、続行したりアイテムを変更したりできる方法はありますか?
#!/usr/bin/python
# togglebuttons.py
import wx
toggle1=[]
toggle2=[]
toggle3=[]
toggle4=[]
toggle5=[]
toggle6=[]
class ToggleButtons(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(300, 300))
self.colour = wx.Colour(0, 0, 0)
wx.ToggleButton(self, 1, '1', (20, 25))
wx.ToggleButton(self, 2, '2', (20, 60))
wx.ToggleButton(self, 3, '3', (20, 100))
wx.ToggleButton(self, 4, '4', (20, 140))
wx.ToggleButton(self, 5, '5', (20, 180))
wx.ToggleButton(self, 6, '6', (20, 220))
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleOne, id=1)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleTwo, id=2)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleThree, id=3)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleFour, id=4)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleFive, id=5)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleSix, id=6)
self.Centre()
self.ShowModal()
self.Destroy()
def ToggleOne(self,event):
if toggle1:
toggle1.remove()
else: toggle1.append(1)
def ToggleTwo(self,event):
if toggle2:
toggle2.remove()
else: toggle2.append(1)
def ToggleThree(self,event):
if toggle3:
toggle3.remove()
else: toggle3.append(1)
def ToggleFour(self,event):
if toggle4:
toggle4.remove()
else: toggle4.append(1)
def ToggleFive(self,event):
if toggle5:
toggle5.remove()
else: toggle5.append(1)
def ToggleSix(self,event):
if toggle6:
toggle6.remove()
else: toggle6.append(1)
app = wx.App(0)
ToggleButtons(None, -1, 'togglebuttons.py')
app.MainLoop()