krishnakant Mane
- A quick and dirty solution as starting point for learning.
- I wrote it to brush up my knowledge on sizers.
Sizers gurus
- Comments and corrections are welcome.
- Is there some way to lock the frame size in one direction only? In that case,
the height. I have attempt several things like SizeHints without to much success.
Jean-Michel Fauth, Switzerland.
# -*- coding: iso-8859-1 -*-
···
#--------------------------------------------------------------------
# Name: dummy.py
# Purpose: On sizers...
# Author: Jean-Michel Fauth, Switzerland
# Copyright: (c) 2007 Jean-Michel Fauth
# Licence: ---
#--------------------------------------------------------------------
# os dev: w2k sp4
# py dev: Python 2.5
# wx dev: wxPython 2.8.0.1
# Revision: ... 2006
#--------------------------------------------------------------------
import wx
#--------------------------------------------------------------------
class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.parent = parent
#vision problems? font size!
self.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
lab1 = wx.StaticText(self, -1, 'hydrogen:', style=wx.ALIGN_RIGHT)
lab2 = wx.StaticText(self, -1, 'tin :', style=wx.ALIGN_RIGHT)
lab3 = wx.StaticText(self, -1, 'mendelevium :', style=wx.ALIGN_RIGHT)
lab4 = wx.StaticText(self, -1, 'carbon :', style=wx.ALIGN_RIGHT)
lab5 = wx.StaticText(self, -1, 'nitogen :', style=wx.ALIGN_RIGHT)
lab6 = wx.StaticText(self, -1, 'argon :', style=wx.ALIGN_RIGHT)
lab7 = wx.StaticText(self, -1, 'iron :', style=wx.ALIGN_RIGHT)
lab8 = wx.StaticText(self, -1, 'gold :', style=wx.ALIGN_RIGHT)
txt1 = wx.TextCtrl(self, -1, '')
txt2 = wx.TextCtrl(self, -1, '')
txt3 = wx.TextCtrl(self, -1, '')
txt4 = wx.TextCtrl(self, -1, '')
txt5 = wx.TextCtrl(self, -1, '')
txt6 = wx.TextCtrl(self, -1, '')
txt7 = wx.TextCtrl(self, -1, '')
txt8 = wx.TextCtrl(self, -1, '')
b1 = wx.Button(self, wx.NewId(), 'Use')
b2 = wx.Button(self, wx.NewId(), 'the')
b3 = wx.Button(self, wx.NewId(), 'wonderful')
b4 = wx.Button(self, wx.NewId(), 'sizer')
b5 = wx.Button(self, wx.NewId(), 'world')
b6 = wx.Button(self, wx.NewId(), '&OK')
b = 10
sizer1 = wx.FlexGridSizer(4, 4, b, b)
sizer1.AddMany([
(lab1, 1, wx.EXPAND | wx.ALL),
(txt1, 1, wx.EXPAND | wx.ALL),
(lab2, 1, wx.EXPAND | wx.ALL),
(txt2, 1, wx.EXPAND | wx.ALL),
(lab3, 1, wx.EXPAND | wx.ALL),
(txt3, 1, wx.EXPAND | wx.ALL),
(lab4, 1, wx.EXPAND | wx.ALL),
(txt4, 1, wx.EXPAND | wx.ALL),
(lab5, 1, wx.EXPAND | wx.ALL),
(txt5, 1, wx.EXPAND | wx.ALL),
(lab6, 1, wx.EXPAND | wx.ALL),
(txt6, 1, wx.EXPAND | wx.ALL),
(lab7, 1, wx.EXPAND | wx.ALL),
(txt7, 1, wx.EXPAND | wx.ALL),
(lab8, 1, wx.EXPAND | wx.ALL),
(txt8, 1, wx.EXPAND | wx.ALL),
])
sizer1.AddGrowableCol(1)
sizer1.AddGrowableCol(3)
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
b = 5
sizer2.Add(b1, 0, border=b)
sizer2.Add(b2, 0, wx.LEFT, b)
sizer2.Add(b3, 0, wx.LEFT, b)
sizer2.Add(b4, 0, wx.LEFT, b)
sizer2.Add(b5, 0, wx.LEFT, b)
sizer2.Add(b6, 0, wx.LEFT, b)
sizer3 = wx.BoxSizer(wx.VERTICAL)
b = 10
sizer3.Add(sizer1, 1, wx.GROW | wx.ALL, b)
sizer3.Add(sizer2, 0, wx.ALIGN_CENTER | wx.ALL, b)
#~ sizer3.SetMinSize((800, 200))
self.SetSizer(sizer3)
self.parent.SetClientSize(sizer3.GetMinSize())
self.CentreOnParent()
#--------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'SimpleApp', wx.DefaultPosition, wx.DefaultSize, wx.DEFAULT_FRAME_STYLE)
self.panel = MyPanel(self, wx.ID_ANY)
#--------------------------------------------------------------------
app = wx.PySimpleApp()
frame = MyFrame(None, wx.ID_ANY)
frame.Show()
app.MainLoop()
#eof-----------------------------------------------------------------