Sizers... - wxPython
Ok, so I'm learning about sizers in wxPython and I was wondering if it was possible to do something like:
==============================================
|WINDOW TITLE _ [] X|
|============================================|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxNOTEBOOKxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
|________ ___________|
|IMAGE | |LoginForm |
|________| |___________|
==============================================
NOTE:Yeah, I literally got this from wxPython - picking the right sizer to use in an application
With NOTEBOOK expanded to left and bottom, IMAGE to align to left and bottom and loginform align to right and bottom and I managed to do almost everything but now I have a problem..
The problem is that I can't align Loginform and Image separately (im using Box Sizers), and I would like to.
EDIT: So everyone can see what I mean: "Oh and what I was referring to开发者_JS百科, was basically that if I changed the align, it would affect both LoginForm and Image.. For example if I set the align to RIGHT, both image and loginform would have been aligned to the right because of: sizer.Add(sizer4,0, wx.ALIGN_RIGHT | wx.RIGHT, 10). Hope you guys can understand this time"
This is the code I'm using that is causing the problem at the moment, any help is appreciated. NOTE:The code might be (HUGELY) sloppy as I'm still learning box sizers. Heres a test code:
import wx
class Sizerframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'sizertestframe',size=(790, 524))
p = wx.Panel(self)
nb = wx.Notebook(p, size = (750, 332))
button = wx.Button(p, -1, "loginform1rest", size=(94,23))
button1 = wx.Button(p, -1, "Login", size=(94,23))
button2 = wx.Button(p, -1, "Cancel", size=(94,23))
imagebutton = wx.Button(p, -1, "imagebutton", size=(94,23))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer1 = wx.BoxSizer(wx.HORIZONTAL)
sizer1.Add(nb,1, wx.EXPAND)
sizer.Add(sizer1,1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
sizer.Add((-1, 25))
sizer2 = wx.BoxSizer(wx.VERTICAL)
sizer2.Add(button, 0)
sizer3 = wx.BoxSizer(wx.HORIZONTAL)
sizer3.Add(button1, 0)
sizer3.Add(button2,0, wx.LEFT, 5)
sizer2.Add(sizer3, 0)
sizer4 = wx.BoxSizer(wx.HORIZONTAL)
sizer4.Add(imagebutton, 1, wx.LEFT | wx.BOTTOM)
sizer4.Add(sizer2,0, wx.RIGHT | wx.BOTTOM , 5)
sizer.Add(sizer4,0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
p.SetSizer(sizer)
def main():
app = wx.App()
frame = Sizerframe()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
How about something like this?
container = wx.BoxSizer(wx.VERTICAL)
container.Add(self.nb, 1, wx.EXPAND)
login = wx.BoxSizer(wx.VERTICAL)
login.Add(self.userLabel)
login.Add(self.userText)
# ... clip, rest of login form additions here
bottom = wx.BoxSizer(wx.HORIZONTAL)
bottom.Add(image)
bottom.Add((0, 0), 1, wx.EXPAND)
bottom.Add(login)
container.Add(bottom, 1, wx.EXPAND)
Basically, the bottom.Add((0, 0), 1, wx.EXPAND)
will act as a spacer that'll take up all the space between the image and the login form. I didn't really understand what you meant by "The problem is that I can't align Loginform and Image separately (im using Box Sizers), and I would like to". I mostly just followed the illustration in trying to create a layout. I hope this helps.
Just tagging on here, I've always found it's easier to make a skeleton of code in wxFormBuilder and then add the code to your project, as opposed to trial-and-error in pure Python.
精彩评论