0

Sorry if this is in the wrong thread, I haven't been here in a long time.

Hi, I'm having a hard time in trying to position my wx.StaticText and wx.TextCtrl so that it's not stuck at the very top and very left. Life so

Screenshot Here

Here is the code

import sqlite3
import sys
import os
import wx

class add (wx.Frame):
             def __init__(self, parent, id):
                 wx.Frame.__init__(self, parent, id, '', size=(660,450), style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
                 self.panel = wx.Panel(self)
                 self.Centre()

                 fnameLabel = wx.StaticText(self.panel, -1, 'First Name: ')
                 self.fname = wx.TextCtrl(self.panel, -1, "", size=(200, -1))
                 fnameLabel.SetFont(wx.Font (10, wx.SWISS, wx.NORMAL, wx.BOLD))
                 self.fname.SetInsertionPoint(0)

                 #Create sizer
                 sizer = wx.FlexGridSizer(cols = 2 , hgap = 4, vgap = 10)
                 sizer.AddGrowableCol(1)

                 sizer.Add(fnameLabel, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                 sizer.Add(self.fname, 0)

                 sizer.Add((50,50))

                 self.panel.SetSizer(sizer)
        

if __name__=='__main__':
    app = wx.App()
    frame = add(parent = None, id = -1)
    frame.Show()
    app.MainLoop()

Thanks in advance for any and all your help.

2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by Megabyte89
2

Your description was not very clear, not sure how you want to layout your control.
You can try this below, it adds some padding.

sizer.Add(fnameLabel, 0, wx.ALIGN_RIGHT|wx.TOP|wx.LEFT, 5)
                 sizer.Add(self.fname, 0, wx.RIGHT|wx.TOP|wx.LEFT, 5)
Votes + Comments
short and efficient
0

Your description was not very clear, not sure how you want to layout your control.
You can try this below, it adds some padding.

sizer.Add(fnameLabel, 0, wx.ALIGN_RIGHT|wx.TOP|wx.LEFT, 5)
                 sizer.Add(self.fname, 0, wx.RIGHT|wx.TOP|wx.LEFT, 5)

Thank You very much cghtkh. You solution worked perfectly.

Edited by Megabyte89: grammar

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.