I am following a tutorial to try to learn to use Wxpython, so I do not fully understand what is going on yet, but when I run the following code it seems like a text dialog box should appear and ask me for my name, however the dialog box does not appear and thus the nameA variable is not assigned a value so I get the error below. What am I doing wrong?
Python Program:
import wx
class main(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "Test Window", size = (300, 200))
panel = wx.Panel(self)
text= wx.TextEntryDialog(None, "What is your name?", "Title", " ")
if text.ShowModal == wx.ID_OK:
nameA = text.GetValue()
wx.StaticText(panel, -1, nameA, (10, 10))
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = main(parent=None, id= -1)
frame.Show()
app.MainLoop()
The error I recieve:
Traceback (most recent call last):
File "C:\Users\Taylor Lunt\Desktop\deleteme.py", line 17, in <module>
frame = main(parent=None, id= -1)
File "C:\Users\Taylor Lunt\Desktop\deleteme.py", line 12, in __init__
wx.StaticText(panel, -1, nameA, (10, 10))
UnboundLocalError: local variable 'nameA' referenced before assignment