i want that when user select multiple buttons, it print all button’s name. I
have added all the buttons with there name in an array but don’t know how to get its labeled name when user click this.
i have attached the code file
raman.py (1.8 KB)
i want that when user select multiple buttons, it print all button’s name. I
have added all the buttons with there name in an array but don’t know how to get its labeled name when user click this.
i have attached the code file
raman.py (1.8 KB)
Your OnClick method is declared at the same level of indentation as the code inside your loop, and thus it belongs to your InitUI method not your frame.
--
James Scholes
http://twitter.com/JamesScholes
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title,size = (1000,800))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
p = wx.Panel(self)
gs = wx.GridSizer(11, 18, 5, 1)
A = [ "H", " "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", "He", "Li", "Be"," "," "," "," "," "," "," "," "," "," ", "B" , "C", "N", "O", "F" , "Ne", "Na", "Mg"," "," "," "," "," "," "," "," "," "," ", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca","Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru","Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "" , "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "", "Rf", "Db", "Sg", "Bh", "Hs","Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og",
" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ", " ", " "," ", " ", " ", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm","Yb", "Lu"," ", " ", " ","Ac", "Th" , "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk","Cf", "Es", "Fm", "Md" , "No", "Lr"," "," "," "," "," "," "," "," "," " ,"Go"," "," "," "," "," "," "," "," " ]
for i in A:
btn = str(i)
a = wx.Button(self, 10, "str(i)", (20,20)) #Buttons are added
a.myname = "str(i)"
#self.Bind(wx.EVT_BUTTON, self.OnClick, a) ## AttributeError: 'Example' object has no attribute 'OnClick'
print(i)
def OnClick(self, event): #When the button is clicked
name = event.GetEventObject().myname
p.SetSizer(gs)
app = wx.App()
Example(None, title = 'Grid demo')
app.MainLoop()
'''
'''
Python is sensitive to whitespace.
Karsten
On Wed, Jun 14, 2017 at 01:18:08PM +0200, firefox@firemail.cc wrote:
#self.Bind(wx.EVT_BUTTON, self.OnClick, a) ## AttributeError: 'Example' object has no attribute 'OnClick'
--
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
well, in Boa Constructor + PyCrust it is well doable. Want the code ?
On 01.06.2017 11:03, Himanshu Pareek wrote:
i want that when user select multiple buttons, it print all button's name. I have added all the buttons with there name in an array but don't know how to get its labeled name when user click this.
We've been through this before. Your __init__ and InitUI instance methods are defined at a 3-space level of whitespace. Your OnClick handler is defined with 7 spaces, so it doesn't belong to your wx.Frame instance, it belongs to your for loop. This is not what you want.
--
James Scholes
http://twitter.com/JamesScholes
import wx
global p , gs
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title,size = (500,300))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
global p , gs
p = wx.Panel(self)
gs = wx.GridSizer(11, 18, 5, 1)
A = [ "He1", "He2 ","Ar3 " ] # put more in if u want
ii = 1
for i in A:
btnl = i
xx = 100 * ii
a = wx.Button(self, 10, btnl, (xx,20))
# 3 Buttons are added and placed aside of each other
a.myname = i
self.Bind(wx.EVT_BUTTON, self.OnClick, a)
print i
ii = ii + 1
#When the button is clicked
def OnClick(self, event):
global p , gs
name = event.GetEventObject().myname
p.SetSizer(gs)
print "onclick is active " + str(name)
app = wx.App()
Example(None, title = 'Grid demo on-clicker')
app.MainLoop()
Hi,
import wx
global p , gs
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title,size =
(500,300))
self.InitUI()
self.Centre()
self.Show()def InitUI(self):
global p , gs
p = wx.Panel(self)
gs = wx.GridSizer(11, 18, 5, 1)
A = [ "He1", "He2 ","Ar3 " ] # put more in if u want
ii = 1
for i in A:
btnl = i
xx = 100 * ii
a = wx.Button(self, 10, btnl, (xx,20))
# 3 Buttons are added and placed aside of each other
a.myname = i
self.Bind(wx.EVT_BUTTON, self.OnClick, a)
print i
ii = ii + 1#When the button is clicked
def OnClick(self, event):
global p , gs
name = event.GetEventObject().myname
p.SetSizer(gs)
print "onclick is active " + str(name)app = wx.App()
Example(None, title = 'Grid demo on-clicker')
app.MainLoop()
You do realize that this code is completely unportable?
And you have a sizer that is never used, but instead you hardcoded
position/size of the controls.
Please check wxPython demo on how to work with sizers and change
your code accordingly.
Thank you.
On Wed, Jun 14, 2017 at 11:26 AM, <firefox@firemail.cc> wrote:
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Please check wxPython demo on how to work with sizers and change
your code accordingly.
I only later found out that the OP had already fixed everything in his github, incl. sizers and what not...
It seems like you're having trouble with building an interactive Periodic
Table of Elements that responds to events. If you're interested, an
example of such a thing is at:
https://github.com/xraypy/xraylarch/blob/master/plugins/wx/periodictable.py
It may not be perfect (suggestions welcome) but it's self contained and
works well for me as a panel component embedded in a couple of applications
where I overload the "onselect" action. It may give you some ideas for how
this sort of thing can be implemented.
Cheers,
--Matt Newville
On Wed, Jun 14, 2017 at 11:26 AM, <firefox@firemail.cc> wrote:
import wx
global p , gs
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title,size =
(500,300))
self.InitUI()
self.Centre()
self.Show()def InitUI(self):
global p , gs
p = wx.Panel(self)
gs = wx.GridSizer(11, 18, 5, 1)
A = [ "He1", "He2 ","Ar3 " ] # put more in if u want
ii = 1
for i in A:
btnl = i
xx = 100 * ii
a = wx.Button(self, 10, btnl, (xx,20))
# 3 Buttons are added and placed aside of each other
a.myname = i
self.Bind(wx.EVT_BUTTON, self.OnClick, a)
print i
ii = ii + 1#When the button is clicked
def OnClick(self, event):
global p , gs
name = event.GetEventObject().myname
p.SetSizer(gs)
print "onclick is active " + str(name)app = wx.App()
Example(None, title = 'Grid demo on-clicker')
app.MainLoop()