2

I've been trying to produce something that allows me to have multiple sentences in a line. The code is:

import wx app = wx.PySimpleApp() class MyDialog(wx.Frame): """ This is my dialog in which I have my interface. """ def __init__(self): """ This stores all my variables. """ wx.Frame.__init__(self, None, -1, "Edit Action", size=(400, 300)) self.my_mini_panels = [] self.my_mini_hboxes = [] self.my_mini_vboxes = [] self.main_vbox = wx.BoxSizer(wx.VERTICAL) self.main_hbox = wx.BoxSizer(wx.HORIZONTAL) self.my_mini_panels.append(wx.Panel(self, -1, style=wx.SIMPLE_BORDER, size=(400, 20))) self.my_mini_hboxes.append(wx.BoxSizer(wx.HORIZONTAL)) self.my_mini_vboxes.append(wx.BoxSizer(wx.VERTICAL)) self.my_mini_hboxes[0].AddMany((wx.StaticText(self.my_mini_panels[0], -1, 'Here it is... '), wx.StaticText(self.my_mini_panels[0], -1, 'There it was.'))) self.my_mini_panels.append(wx.Panel(self, -1, style=wx.SIMPLE_BORDER, size=(400, 20))) self.my_mini_hboxes.append(wx.BoxSizer(wx.HORIZONTAL)) self.my_mini_vboxes.append(wx.BoxSizer(wx.VERTICAL)) self.my_mini_hboxes[1].AddMany((wx.StaticText(self.my_mini_panels[1], -1, 'Hello, '), wx.StaticText(self.my_mini_panels[1], -1, 'Goodbye!'))) for i, hbox in enumerate(self.my_mini_hboxes): hbox.Add(self.my_mini_vboxes[i]) self.main_vbox.AddMany(tuple(self.my_mini_hboxes)) self.main_hbox.Add(self.main_vbox) self.SetSizer(self.main_hbox) if __name__ == '__main__': dialog = MyDialog() dialog.Show(True) app.MainLoop() 

It doesn't seem to be working. I'd like it to look like this:enter image description here

What am I doing wrong?

EDIT

Perhaps I should make it clear that the static text objects must be separate. I can't just replace two segments of text on one line with one larger segment.

1 Answer 1

1

You don't need lots of sizers and panels for this. You can use one panel + one sizer + two static text widgets. Here's the code:

import wx class MyDialog(wx.Frame): """ This is my dialog in which I have my interface. """ def __init__(self): """ This stores all my variables. """ wx.Frame.__init__(self, None, -1, "Edit Action", size=(400, 300)) panel = wx.Panel(self) main_vbox = wx.BoxSizer(wx.VERTICAL) label_one = wx.StaticText(panel, label="Here it is... There it was.") label_two = wx.StaticText(panel, label="Hello, Goodbye!") main_vbox.Add(label_one, 0, wx.ALL, 5) main_vbox.Add(label_two, 0, wx.ALL, 5) panel.SetSizer(main_vbox) if __name__ == '__main__': app = wx.App(False) dialog = MyDialog() dialog.Show(True) app.MainLoop() 

Note also that I changed your app object from wx.PySimpleApp to just wx.App. The wx.PySimpleApp has been deprecated and it is recommended to use wx.App from now on.

You might consider sub-classing from wx.Dialog instead of wx.Frame as that would make more sense if this is really supposed to be a dialog.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.