0
我有三個對話框(命名爲:BOX1,BOX2和BOX3)工作從兩個對話框中顯示的文本,如下圖所示: -wxPython中 - 印在第三個對話框
基本計算都在BOX1和BOX2中進行,我如何顯示第三個對話框的計算總和,即在Box3上?
import wx
class Box1 (wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__ (self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size(500,141), style = wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
bSizer42 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText61 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item1", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText61.Wrap(-1)
bSizer42.Add(self.m_staticText61, 0, wx.ALL, 5)
self.m_staticText62 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item2", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText62.Wrap(-1)
bSizer42.Add(self.m_staticText62, 0, wx.ALL, 5)
bSizer8.Add(bSizer42, 0, wx.EXPAND, 5)
bSizer43 = wx.BoxSizer(wx.VERTICAL)
bSizer43.AddSpacer((80, 0), 1, wx.EXPAND, 5)
bSizer8.Add(bSizer43, 0, wx.EXPAND, 5)
bSizer11 = wx.BoxSizer(wx.VERTICAL)
self.item1 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"7.50", wx.DefaultPosition, wx.Size(-1,20), 0)
bSizer11.Add(self.item1, 0, wx.ALL, 5)
self.item2 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"8.00", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer11.Add(self.item2, 0, wx.ALL, 5)
bSizer8.Add(bSizer11, 0, 0, 5)
self.m_panel2.SetSizer(bSizer8)
self.m_panel2.Layout()
bSizer8.Fit(self.m_panel2)
bSizer6.Add(self.m_panel2, 1, wx.EXPAND |wx.ALL, 5)
bSizer13 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText25 = wx.StaticText(self, wx.ID_ANY, u"Quatity:", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText25.Wrap(-1)
self.m_staticText25.SetFont(wx.Font(15, 70, 90, 92, False, wx.EmptyString))
bSizer13.Add(self.m_staticText25, 0, wx.ALL|wx.EXPAND, 5)
quantity_choiceChoices = [ u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10" ]
self.quantity_choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, quantity_choiceChoices, 0)
self.quantity_choice.SetSelection(0)
bSizer13.Add(self.quantity_choice, 0, wx.ALL, 5)
self.ok_button = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.ok_button, 1, wx.ALL|wx.EXPAND, 5)
self.cancel_button = wx.Button(self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.cancel_button, 1, wx.ALL, 5)
bSizer6.Add(bSizer13, 0, wx.EXPAND, 5)
self.SetSizer(bSizer6)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
self.ok_button.Bind(wx.EVT_BUTTON, self.okFunc)
self.cancel_button.Bind(wx.EVT_BUTTON, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
def okFunc(self, event):
quatity_choice = int(self.quantity_choice.GetStringSelection())
if self.item1.GetValue():
price = quatity_choice * 7.5
print price
if self.item2.GetValue():
price = quatity_choice * 8.0
print price
Box2(None).ShowModal()
class Box2 (wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__ (self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size(500,141), style = wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
bSizer42 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText61 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item3", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText61.Wrap(-1)
bSizer42.Add(self.m_staticText61, 0, wx.ALL, 5)
self.m_staticText62 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item4", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText62.Wrap(-1)
bSizer42.Add(self.m_staticText62, 0, wx.ALL, 5)
bSizer8.Add(bSizer42, 0, wx.EXPAND, 5)
bSizer43 = wx.BoxSizer(wx.VERTICAL)
bSizer43.AddSpacer((80, 0), 1, wx.EXPAND, 5)
bSizer8.Add(bSizer43, 0, wx.EXPAND, 5)
bSizer11 = wx.BoxSizer(wx.VERTICAL)
self.item3 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"1.50", wx.DefaultPosition, wx.Size(-1,20), 0)
bSizer11.Add(self.item3, 0, wx.ALL, 5)
self.item4 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"2.00", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer11.Add(self.item4, 0, wx.ALL, 5)
bSizer8.Add(bSizer11, 0, 0, 5)
self.m_panel2.SetSizer(bSizer8)
self.m_panel2.Layout()
bSizer8.Fit(self.m_panel2)
bSizer6.Add(self.m_panel2, 1, wx.EXPAND |wx.ALL, 5)
bSizer13 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText25 = wx.StaticText(self, wx.ID_ANY, u"Quatity:", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText25.Wrap(-1)
self.m_staticText25.SetFont(wx.Font(15, 70, 90, 92, False, wx.EmptyString))
bSizer13.Add(self.m_staticText25, 0, wx.ALL|wx.EXPAND, 5)
add_quantity_choiceChoices = [ u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10" ]
self.add_quantity_choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, add_quantity_choiceChoices, 0)
self.add_quantity_choice.SetSelection(0)
bSizer13.Add(self.add_quantity_choice, 0, wx.ALL, 5)
self.ok_button = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.ok_button, 1, wx.ALL|wx.EXPAND, 5)
self.cancel_button = wx.Button(self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.cancel_button, 1, wx.ALL, 5)
bSizer6.Add(bSizer13, 0, wx.EXPAND, 5)
self.SetSizer(bSizer6)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
self.ok_button.Bind(wx.EVT_BUTTON, self.okFunc)
self.cancel_button.Bind(wx.EVT_BUTTON, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
def okFunc(self, event):
add_quatity_choice = int(self.add_quantity_choice.GetStringSelection())
if self.item3.GetValue():
add_price = add_quatity_choice * 1.5
print add_price
if self.item4.GetValue():
add_price = add_quatity_choice * 2.0
print add_price
Box3(None).ShowModal()
class Box3 (wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__ (self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size(257,165), style = wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer13 = wx.BoxSizer(wx.VERTICAL)
self.totalText = wx.StaticText(self, wx.ID_ANY, u"Total is:", wx.DefaultPosition, wx.DefaultSize, 0)
self.totalText.Wrap(-1)
self.totalText.SetFont(wx.Font(20, 70, 90, 90, False, wx.EmptyString))
bSizer13.Add(self.totalText, 0, wx.ALL|wx.EXPAND, 5)
self.totalText1 = wx.StaticText(self, wx.ID_ANY, u"?", wx.DefaultPosition, wx.DefaultSize, 0)
self.totalText1.Wrap(-1)
self.totalText1.SetFont(wx.Font(20, 70, 90, 90, False, wx.EmptyString))
self.totalText1.SetLabel(str('price + add_price'))
# How to I get the "price + add_price" printed above
bSizer13.Add(self.totalText1, 0, wx.ALL, 5)
self.SetSizer(bSizer13)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
app = wx.App(0)
Box1(None).Show()
app.MainLoop()
正在對BOX1和BOX2進行
簡單的算術,我想第三個對話框(BOX3)
如何完成這件事上要顯示的結果的總和?
的代碼是基於wxPython的經典和Python 2.7
偉大的工作。 –