views:

28

answers:

1

I create a wx.TextEntryDialog as follows:

import wx

dlg = wx.TextEntryDialog(self, 'Rules:', 'Edit rules', 
                         style=wx.TE_MULTILINE|wx.OK|wx.CANCEL)
dlg.SetValue(self.rules_text.Value)
if dlg.ShowModal() == wx.ID_OK:
    …

This results in a dialog box that is too small for my needs, and that is not resizable:

small dialog box

My question is: How can I make the dialog box larger and resizable? I tried adding the flags wx.DEFAULT_DIALOG_STYLE and wx.RESIZE_BORDER, but that had no effect except to replace the text with dots:

dlg = wx.TextEntryDialog(self, 'Rules:', 'Edit rules', 
                         style=wx.TE_MULTILINE|wx.OK|wx.CANCEL|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)

small, garbled dialog box

+1  A: 

Time to learn how to write your own dialogs! ;-)

The built-in dialogs such as TextEntryDialog are only for the most basic programs. If you need much customization, you need to write your own dialogs.

Here's an example, this should work for you.

import wx

class TextEntryDialog(wx.Dialog):
    def __init__(self, parent, title, caption):
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        super(TextEntryDialog, self).__init__(parent, -1, title, style=style)
        text = wx.StaticText(self, -1, caption)
        input = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
        input.SetInitialSize((400, 300))
        buttons = self.CreateButtonSizer(wx.OK|wx.CANCEL)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, 0, wx.ALL, 5)
        sizer.Add(input, 1, wx.EXPAND|wx.ALL, 5)
        sizer.Add(buttons, 0, wx.EXPAND|wx.ALL, 5)
        self.SetSizerAndFit(sizer)
        self.input = input
    def SetValue(self, value):
        self.input.SetValue(value)
    def GetValue(self):
        return self.input.GetValue()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    dialog = TextEntryDialog(None, 'Title', 'Caption')
    dialog.Center()
    dialog.SetValue('Value')
    if dialog.ShowModal() == wx.ID_OK:
        print dialog.GetValue()
    dialog.Destroy()
    app.MainLoop()
FogleBird