所以我的问题是,我需要在 wxpython 中创建一个 GUI 来计算汉堡包的价格。每个额外的成分是1.55,小价是1.55,中价是1.55加1.55等等。我的问题是:我如何分配单选按钮,就像我想这样做一样:如果选择了 radiobutton1:这样做
与复选框的数量相同。继承人我的脚本到目前为止。
import wx
class Window(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(400, 250))
self.title = title
self.initGUI()
def initGUI(self):
# Set up the widgets for the GUI
panel = wx.Panel(self, -1)
self.amount = wx.StaticText(panel, -1, 'Ingredients = 0', pos=(10, 10))
# Parent ID Value Position (Height, Width)
self.cb1 = wx.CheckBox(panel, -1, 'Extra Patty', (10, 30))
self.cb2 = wx.CheckBox(panel, -1, 'Cheese', (10, 50))
self.cb3 = wx.CheckBox(panel, -1, 'Onions', (10, 70))
self.cb4 = wx.CheckBox(panel, -1, 'Mushrooms', (10,90))
# Register an event for each checkbox.
self.Bind(wx.EVT_CHECKBOX, self.toggleIngredients, self.cb1)
self.Bind(wx.EVT_CHECKBOX, self.toggleIngredients, self.cb2)
self.Bind(wx.EVT_CHECKBOX, self.toggleIngredients, self.cb3)
self.Bind(wx.EVT_CHECKBOX, self.toggleIngredients, self.cb4)
self.rb1 = wx.RadioButton(panel, -1, 'Small', (200,30))
self.rb2 = wx.RadioButton(panel, -1, 'Medium', (200,50))
self.rb3 = wx.RadioButton(panel, -1, 'Large', (200, 70))
self.Show()
self.Centre()
def toggleIngredients(self, event):
self.ingredients = 0
for cb in (self.cb1, self.cb2, self.cb3, self.cb4):
if cb.IsChecked():
self.ingredients += 1
self.amount.SetLabel('Ingredients = ' + str(self.ingredients))
if self.amount.SetLabel == '1':
ing = 1
if self.amount.SetLabel == '2':
ing = 2
if self.amount.SetLabel == '3':
ing = 3
if self.amount.SetLabel == '4':
ing = 4
app = wx.App(False)
window = Window(None, 'CheckBox Example')
app.MainLoop()