How to call a class objects's method if it is not assigned to a variable in python? -
please see code below, how call getcurrentselection()
method of choice()
object below? choice()
object not assigned variable.
import wx class choiceframe(wx.frame): def __init__(self): wx.frame.__init__(self, none, -1, 'choice example', size=(250, 200)) panel = wx.panel(self, -1) samplelist = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'] wx.statictext(panel, -1, "select one:", (15, 20)) wx.choice(panel, -1, (85, 18), choices=samplelist) if __name__ == '__main__': app = wx.pysimpleapp() choiceframe().show() app.mainloop()
if written way:
choice_object = wx.choice(panel, -1, (85, 18), choices=samplelist)
then do:
choice_object.getcurrentselection()
but has no variable names, how call getcurrentselection()
method in original code above?
you search through children of top panel looking since haven't given name hard pressed match - best bet assign need interface later self.member e.g. self.mychoice = ...
or array or dictionary member of self
.
the other option, if don't adding properties list, extend class on creation takes data item associate with, initialises current value , binds appropriate change events setting value in item.
Comments
Post a Comment