I have a little project im working on, and the fundamentals are fine, i just have two specific queries. I have learned the code shown here from scratch the past week from samples and tutorials plus a little outside the box thinking.

My only problem now is that my two queries are too specific for me to find in a search engine or guide.

problem 1: I need the static text title to fill the full proportion of the slot it is in, sort of half the vertical size of the button but just as wide. I would also like advice on how to put a picture or logo in place of the text.

problem 2: I need to know how to drop a line when putting text on a button, ive tried /n //n //N but it always comes up as part of the string.

i would greatly appreciate advice on both these problems and any comments/criticisms about my layout ect.

Thanks.

import wx

class Sample(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Sample Code', size = (250, 350))
        panel1 = wx.Panel(self)
        
        title = wx.StaticText(panel1, wx.ALIGN_CENTRE, "HUGE CENTRED TITLE")
        rndmbtn = wx.Button(panel1, label = "Random //n Button")

        vrtspc1 = wx.BoxSizer(wx.VERTICAL)
        vrtspc2 = wx.BoxSizer(wx.VERTICAL)
        hzlspc1 = wx.BoxSizer()
        hzlspc2 = wx.BoxSizer()
        hzlspc3 = wx.BoxSizer()

        vertbox2 = wx.BoxSizer(wx.VERTICAL)
        vertbox2.Add(hzlspc1, proportion = 1, border = 0)
        vertbox2.Add(title, proportion = 2, flag = wx.EXPAND, border = 0)
        vertbox2.Add(hzlspc2, proportion = 1, border = 0)
        vertbox2.Add(rndmbtn, proportion = 4, flag = wx.EXPAND, border = 0)
        vertbox2.Add(hzlspc3, proportion = 1, border = 0)
        
        layoutmgr = wx.BoxSizer()
        layoutmgr.Add(vrtspc1, proportion = 1, border = 0)
        layoutmgr.Add(vertbox2, proportion = 5, flag = wx.EXPAND, border = 0)
        layoutmgr.Add(vrtspc2, proportion = 1, border = 0)
        
        panel1.SetSizer(layoutmgr)

app = wx.App(redirect = False)
frame = Sample(parent = None, id = -1)
frame.Show()
app.MainLoop()

can anyone help?

Well, you can put other widgets (wx.StaticText or wx.StaticBitmap) on the button, in this case 2 labels each showing a line of text ...

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle):
        wx.Frame.__init__(self, parent, -1, mytitle, size=(275, 300))
        panel = wx.Panel(self)
        
        s = "HUGE CENTRED TITLE"
        face = "Comic Sans MS"
        font = wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL, False, face)
        label = wx.StaticText(panel, label=s, style=wx.ALIGN_CENTRE)
        label.SetFont(font)
        
        button = wx.Button(panel, size=(140, 75))
        # put labels on button and position to your need
        btn_text = wx.StaticText(button, label="Random", pos=(50,10))
        btn_text = wx.StaticText(button, label="Button", pos=(50,25))
        
        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(label, 0, flag=wx.ALL, border=10) 
        sizer_v.Add(button, 0, flag=wx.ALL, border=10) 
        panel.SetSizer(sizer_v)


app = wx.App(0)
MyFrame(None, 'wx.button()').Show()
app.MainLoop()

ive solved the issue with the button. I was typing /n instead of \n.

Thanks for your help, the title advice was spot on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.