Advertisement
furas

Python - wxPython - GridSizer

Jun 1st, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. #
  2. # image: http://imgur.com/bJQL9Qb.png
  3. #
  4.  
  5. import wx
  6.  
  7. class Example(wx.Frame):
  8.  
  9.    A = [
  10.        "H", " ", " ", " ", " ", " ", " ", " ", " ",
  11.        " "," "," "," "," "," "," "," ", "He",
  12.        "Li", "Be"," "," "," "," "," "," "," ",
  13.        " "," "," ", "B" , "C", "N", "O", "F" ,
  14.        "Ne", "Na", "Mg"," "," "," "," "," ",
  15.        " "," "," "," "," ", "Al", "Si", "P",
  16.        "S", "Cl", "Ar", "K", "Ca","Sc", "Ti",
  17.        "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu",
  18.        "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
  19.        "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc",
  20.        "Ru","Rh", "Pd", "Ag", "Cd", "In", "Sn",
  21.        "Sb", "Te", "I", "Xe", "Cs", "Ba", "" ,
  22.        "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt",
  23.        "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At",
  24.        "Rn", "Fr", "Ra", "", "Rf", "Db", "Sg",
  25.        "Bh", "Hs","Mt", "Ds", "Rg", "Cn", "Nh",
  26.        "Fl", "Mc", "Lv", "Ts", "Og",
  27.         " "," "," "," "," "," "," "," "," "," ",
  28.        " "," "," "," "," "," ", " ", " "," ", " ", " ",
  29.        "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd",
  30.        "Tb", "Dy", "Ho", "Er", "Tm","Yb", "Lu"," ", " ",
  31.        " ","Ac", "Th" , "Pa", "U", "Np", "Pu", "Am",
  32.        "Cm", "Bk","Cf", "Es", "Fm", "Md" , "No", "Lr",
  33.        " "," "," "," "," "," "," "," "," " ,"Go",
  34.        " "," "," "," "," "," "," "," "
  35.    ]
  36.    
  37.    def __init__(self, parent, title):
  38.        super(Example, self).__init__(parent, title = title,size = (1000,800))
  39.              
  40.        self.InitUI()
  41.        self.Centre()
  42.        self.Show()      
  43.  
  44.    def OnClick(self, event):  #When the button is clicked
  45.        name = event.GetEventObject().myname
  46.      
  47.    def InitUI(self):
  48.    
  49.        p = wx.Panel(self)
  50.        gs = wx.GridSizer(11, 18, 5, 1)
  51.        p.SetSizer(gs)
  52.        
  53.        for txt in self.A:
  54.            print(txt)
  55.            if txt != ' ':
  56.                # you need `p` instead of `self`
  57.                btn = wx.Button(p, 10, txt, (20, 20))
  58.                btn.myname = txt
  59.                self.Bind(wx.EVT_BUTTON, self.OnClick, btn)
  60.                gs.Add(btn, 0, wx.EXPAND) #Buttons are added
  61.            else:
  62.                gs.Add(wx.StaticText(p, label=''), 0, wx.EXPAND)
  63.          
  64.    
  65. app = wx.App()
  66. Example(None, title = 'Grid demo')
  67. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement