wxpython 表格重置_Python/wxPython:如何重置wx.选择默认值

我正在处理多个wx.选择控件中的控件,我需要使用makeasreset按钮来恢复单击时的默认选项“--Select--”。

我最不想实现的是什么,是空的。我希望在按下重置按钮时出现默认选项“--Select--”。请参阅下面的代码。在

数据.pyimport wx

class MyFrame1 ( wx.Frame ):

def __init__( self, parent ):

wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 250,300 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.TAB_TRAVERSAL )

self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

DataBox = wx.BoxSizer( wx.HORIZONTAL )

gSizer2 = wx.GridSizer( 0, 2, 0, 0 )

self.Color_Label = wx.StaticText( self, wx.ID_ANY, u"Color:", wx.DefaultPosition, wx.DefaultSize, 0 )

self.Color_Label.Wrap( -1 )

self.Color_Label.SetFont( wx.Font( 13, 70, 90, 90, False, wx.EmptyString ) )

gSizer2.Add( self.Color_Label, 0, wx.ALL, 5 )

Color_optionsChoices = [ u"-- Select --", u"Red", u"Green", u"Pink", u"Blue", u"Yellow", u"White", u"Brown" ]

self.Color_options = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, Color_optionsChoices, 0 )

self.Color_options.SetSelection( 0 )

gSizer2.Add( self.Color_options, 0, wx.ALL, 5 )

self.Age = wx.StaticText( self, wx.ID_ANY, u"Age:", wx.DefaultPosition, wx.DefaultSize, 0 )

self.Age.Wrap( -1 )

self.Age.SetFont( wx.Font( 13, 70, 90, 90, False, wx.EmptyString ) )

gSizer2.Add( self.Age, 0, wx.ALL, 5 )

Age_optionsChoices = [ u"-- Select --", u"15", u"16", u"17", u"18", u"19", u"20", u"21", u"22", u"23", u"24", u"25", wx.EmptyString ]

self.Age_options = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, Age_optionsChoices, 0 )

self.Age_options.SetSelection( 0 )

gSizer2.Add( self.Age_options, 0, wx.ALL, 5 )

self.Country = wx.StaticText( self, wx.ID_ANY, u"Country:", wx.DefaultPosition, wx.DefaultSize, 0 )

self.Country.Wrap( -1 )

self.Country.SetFont( wx.Font( 13, 70, 90, 90, False, wx.EmptyString ) )

gSizer2.Add( self.Country, 0, wx.ALL, 5 )

Country_optionsChoices = [ u"-- Select --", u"Mexico", u"Peru", u"India", u"USA", u"UK", u"Greece", u"Agentina", u"Greece", u"Brazil", u"Egypt" ]

self.Country_options = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, Country_optionsChoices, 0 )

self.Country_options.SetSelection( 0 )

gSizer2.Add( self.Country_options, 0, wx.ALL, 5 )

self.Reset_button = wx.Button( self, wx.ID_ANY, u"Reset", wx.DefaultPosition, wx.DefaultSize, 0 )

gSizer2.Add( self.Reset_button, 0, wx.ALL, 5 )

self.Exit_button = wx.Button( self, wx.ID_ANY, u"Exit", wx.DefaultPosition, wx.DefaultSize, 0 )

gSizer2.Add( self.Exit_button, 0, wx.ALL, 5 )

DataBox.Add( gSizer2, 1, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 5 )

self.SetSizer( DataBox )

self.Layout()

self.Centre( wx.BOTH )

# Connect Events

self.Reset_button.Bind( wx.EVT_BUTTON, self.OnResetButton )

self.Exit_button.Bind( wx.EVT_BUTTON, self.OnExitButton )

def OnResetButton( self, event ):

# val = '-- Select --' # NOT WORKING

val = ' ' # THIS WORKS, BUT RESETS TO EMPTY CHOICE

self.Color_options.SetLabel(val)

self.Age_options.SetLabel(val)

self.Country_options.SetLabel(val)

def OnExitButton( self, event ):

self.Close()

app = wx.App(0)

MyFrame1(None).Show()

app.MainLoop()

感谢您提前抽出时间。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值