Frage

I have the following piece of code

def create_gui(self):

    main_sizer = wx.GridBagSizer()

    self.main_txt = wx.TextCtrl(self ,-1, value="", style=wx.TE_MULTILINE)
    main_sizer.Add(self.main_txt,(1,0),(10,10),wx.EXPAND) 

    self.input_txt = wx.TextCtrl(self ,-1, value="", style=wx.TE_MULTILINE)
    main_sizer.Add(self.input_txt,(12,0),(5,1),wx.EXPAND) 


    main_sizer.AddGrowableCol(0)
    main_sizer.AddGrowableRow(0)

    self.SetSizerAndFit(main_sizer)
    self.SetSizeHints(600,500,750,650) 
    self.Fit()
    self.Show(True)

The problem is that i cannot control the size of the cells at all. In addition to that anything i do results to chaos. I am currently trying to change the width of th input_txt but 1 is too big and 2 or more adds up only a couple of millimeters (if not at all). I am familiar with Tkinter but WX seems to be too complicated for no good reason. If there is an easier way of doing it please let me know (boxsizer for example), all suggestions are welcome.

War es hilfreich?

Lösung

If you want your controls to resize when the window itself is resized, then you'll want to use sizers. If you don't care about that, you can use absolute positioning and set the size of the widgets yourself.

I personally use wx.BoxSizers for almost everything I do in wxPython. When I have a complex layout, I sketch it out and draw boxes to help me better visualize how to nest the box sizers. When a widget is in a sizer, the sizer will manage the widget's size. So you won't have any control over that except to say how big it is in relation to other sizers (i.e. the proportion value).

Here's a simple example:

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myWidget, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
sizer.Add(myOtherWidget, proportion=0, flag=wx.ALL, border=5)

This example tells wxPython to make the first widget as big as possible without covering up any other widgets. If this widget was a button, you would see a button that takes up 90% or more of the frame with the other widget underneath it. If you want the two widgets to be the same size, you would give them the same proportion. You would also want to pass the wx.EXPAND flag so that they would expand correctly.

I hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top