wx.StaticText not shown in display [solved]

Post here if you need help with creating a Graphical User Interface in Python.

wx.StaticText not shown in display [solved]

Postby merlem » Sun Sep 11, 2016 3:11 pm

Why is wx.StaticText that is added by gbs.Add() not shown in the display?
The window contains empty boxes where text should be, but through them the desktop image is visible.

The code is simple:

Code: Select all
class tabgbs(wx.Frame):
    """ Creates the main frame for the GridBagSizer"""
    def __init__(self, parent, id, title, size):
        wx.Frame.__init__(self, parent, id, title, size)

        gbs = self.gbs = wx.GridBagSizer(hgap=1, vgap=1)


Then I add several elements with

Code: Select all
        gbs.Add(wx.StaticText(self, id, "x"), (rowspos, collspos))


and finally there is:

Code: Select all
        box = wx.BoxSizer()
        box.Add(gbs, 0, wx.ALL|wx.EXPAND)
       
        self.SetSizer(box)
        box.Fit(self)
       
        self.Show()

        return
Last edited by merlem on Sat Sep 17, 2016 3:31 pm, edited 1 time in total.
merlem
 
Posts: 4
Joined: Fri Jul 01, 2016 4:51 pm

Re: wx.StaticText not shown in display (within GridBagSizer)

Postby Yoriz » Tue Sep 13, 2016 6:20 pm

Apart from adding default values for rowspos & collspos and adding a mainloop shown as follows the wx.StaticText shows to me.
WxFrame.jpg
WxFrame.jpg (2.89 KiB) Viewed 999 times

Code: Select all
import wx


class Tabgbs(wx.Frame):
    """ Creates the main frame for the GridBagSizer"""

    def __init__(self, parent, id_, title, size):
        wx.Frame.__init__(self, parent, id_, title, size)

        gbs = self.gbs = wx.GridBagSizer(hgap=1, vgap=1)

        rowspos = 1
        collspos = 2

        gbs.Add(wx.StaticText(self, id_, "x"), (rowspos, collspos))

        box = wx.BoxSizer()
        box.Add(gbs, 0, wx.ALL | wx.EXPAND)

        self.SetSizer(box)
        box.Fit(self)

        self.Show()

        return


app = wx.App(False)
Tabgbs(None, -1, '', (-1, -1))
app.MainLoop()
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: wx.StaticText not shown in display (within GridBagSizer)

Postby merlem » Sat Sep 17, 2016 3:27 pm

Thank you very much, Yoriz!

When writing the code, I was assuming that the mainloop is acting kind of 'main' for the program, but it seems that it was only applied to another frame I created. With an own loop for this frame, it now works.
merlem
 
Posts: 4
Joined: Fri Jul 01, 2016 4:51 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 2 guests