Search code examples
pythoninterfacewxpython

How to make a text dialogue appear in wxpython


I have been looking around the web since early morning and I can't seem to figure out how to get wxPython to show a dialogue box on my main frame.

import wx

class MainWindow(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Window',size=(400,300))
        panel = wx.Panel(self)

        test = wx.TextEntryDialog(panel, 'Enter your word:',"New word","", 
                    style=wx.OK|wx.CANCEL|wx.CENTRE,pos=(100,200))



def main():
    pass

if __name__ == '__main__':
    app = wx.App()
    frame=MainWindow(parent=None,id=1)
    frame.Show()
    app.MainLoop()

It just opens a window without a text dialogue.


Solution

  • Use:

    Dlg = wx.TextEntryDialog(panel, 'Enter your word:',"New word","", 
                    style=wx.OK|wx.CANCEL|wx.CENTRE,pos=(100,200))
    
    if Dlg.ShowModal() == wx.OK:
        test = Dlg.GetValue() 
    del Dlg
    

    As wx.TextEntryDialog is a dialogue class not one of the convenience dialogue functions you need to show it and get the value rather than just getting a reply.